Delete files specified period of time

(imported topic written by SystemAdmin)

What can I do to remove the files that have not been updated in a certain period of time on Windows.

I wrote the following Fixlet, its do not work and enter the file name blank.

delete __appendfile

appendfile {concatination “%0d%0a” of pathnames of files whose ( now - modification time of it > 24 * hour ) of folder “C:\work”}

copy __appendfile “C:\Temp\list.txt”

dos for /F %i in (C:\Temp\list.txt) do del %i

(imported comment written by SystemAdmin)

Hello,

You are very close. 2 small changes:

  1. Concatination was misspelled. It should be concatenation.

  2. C:\TEMP does not exist in all Windows OS’s so if you remove c:\temp\ and just move it to “list.txt” it will run from the client context.

Below is a working example. Time is set to 1 minute and a different folder name for testing purposes.

delete __appendfile

appendfile {concatenation “%0d%0a” of pathnames of files whose ( now - modification time of it > 1 * minute ) of folder “C:\myfolder”}

copy __appendfile list.txt

dos for /F %i in (list.txt) do del %i

(imported comment written by SystemAdmin)

Thank you.

If there is a space in the file name, I can not delete the dos command.

I wonder Is there a way to put double quotes around the file name that you list?

(imported comment written by SystemAdmin)

Hello fkmr,

%22 will be interpreted as a double quote, just like %0d%0a is interpeted as a Carriage return/Line Feed. You would then have to replace (pathnames) with ("%22" & pathnames of it & “%22”)

delete __appendfile

appendfile {concatenation “%0d%0a” of ("%22" & pathname of it & “%22”) of files whose ( now - modification time of it > 1 * minute ) of folder “C:\myfolder”}

copy __appendfile list.txt

dos for /F %i in (list.txt) do del %i

The problem with is is that dos still execute correctly because of the space. You might consider building a batch file on the fly and executing that. This will build a batch file that looks like:

del /F “name of file.txt”

del /F “name of file.doc”

del /F “any other files.file”

The example below worked for files with spaces.

delete __appendfile

appendfile {concatenation “%0d%0a” of (“del /F %22” & pathname of it & “%22”) of files whose ( now - modification time of it > 1 * minute ) of folder “C:\myfolder”}

copy __appendfile list.bat

wait cmd.exe /C list.bat

(imported comment written by SystemAdmin)

thanks much! that works perfectly.