Monday 15 July 2013

windows - Command Line to Delete Files and Folders and Sub Folders in Directory, Except Those Who Were Created Today -



windows - Command Line to Delete Files and Folders and Sub Folders in Directory, Except Those Who Were Created Today -

i want write batch file cleanup downloads folder deleting in except files , folders created today. thanks.

if using modern windows, recommend utilize forfiles,

folder can still messy. want based on timestamp of directory itself? want process recursively through folders, deleting files based on date , delete folder if empty after deleting files of given age. there other reasonable interpretations of question well. personally, utilize python script can create file cleanup want. may why uriil suggested powershell.

arguably, windows services unix downloadable microsoft considered fair game (allowing find command mentioned johnride). if utilize this, create sure johnride suggestion matches actual intent. find command, using alternative -print instead of -exec great debugging

if can utilize forfiles, article may give want. taking liberty of pasting in batch file solution using forfiles article.

@echo off :: set folder path set dump_path=c:\shares\dump :: set min age of files , folders delete set max_days=1 :: remove files %dump_path% forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd /c del /q @path" :: remove sub directories %dump_path% forfiles -p %dump_path% -d -%max_days% -c "cmd /c if @isdir == true rd /s /q @path"

windows batch-file command-line windows-7

No comments:

Post a Comment