Deleting a file that is older than x number of days using a batch file in Windows -
i have been trying write batch file removes files older x
number of days. have backup directory e:\backup2
contains number of sub-folders alresco
, postgres
, sybase
.
these sub-folders contain different internal structuring of files don't think should affect script need through every file in backup2
directory, , if older x
days delete file.
so far have following cannot work:
forfiles /p "e:\backup2" /s /d -2 /c "cmd del /f /q @path"
where 2
defines how old file must in days before can deleted.
when execute command in cmd
of files remain without error being reported.
what interesting when output log file, reports directory first file located..
when first ran command log file reported e:\backup2\alfresco\25072015
when moved log file root directory , re-ran comman log file reported e:\backup2
suggests command finding first log file needs delete , breaks.
from documentation found here have these examples:
examples: delete testfile if is 5 days old or older: c:\> forfiles /m testfile.txt /c "cmd /c del testfile.txt " /d -5 find .xls file last modified 30 days ago or older c:\> forfiles /m *.xls /c "cmd /c echo @path changed 30 days ago" /d -30 list size of .doc files: c:\> forfiles /s /m *.doc /c "cmd /c echo @fsize"
compared code seem miss /c when calling cmd del, code should be:
forfiles /p "e:\backup2" /s /d -2 /c "cmd /c del /f /q @path"
Comments
Post a Comment