last access file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
steff
Posts: 2
Joined: 22 Dec 2015 02:59

last access file

#1 Post by steff » 22 Dec 2015 03:07

Hi
i use a .cmd file to delete all files older than 20days in a drive.

set PFAD=T:\
set TAGE=20

forfiles -p %PFAD% -s -m *.* /D -%TAGE% /C "cmd /c del /Q /F @path"

the problem is that this use the modification date of the file.
is it possible to delete files with the last access is older than 20 days?

because if i copy a file in the drive the modification time don't change.

sorry for the bad english and i hope someone can help me.

greets steff

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: last access file

#2 Post by aGerman » 22 Dec 2015 12:47

ROBOCOPY with options /L and /MINLAD:20 may help to select the files. If you process the output in a FOR /F loop you can perform the deletion.

Code: Select all

for /f "tokens=*" %%i in (
  'robocopy "T:\." "T:\." /l /s /xx /is /it /nc /ns /np /ndl /njh /njs /r:0 /w:0 /minlad:20'
) do ECHO del /f "%%i"

Note that the FOR /F loop buffers the whole output of ROBOCOPY in memory before it even begins to iterate. That will take as much time as it takes to process each file on you drive.
Remove the ECHO if you are sure the right files were found.

Regards
aGerman

steff
Posts: 2
Joined: 22 Dec 2015 02:59

Re: last access file

#3 Post by steff » 28 Dec 2015 05:00

hey aGerman

thanks a lot it works perfekt.

oder auf deutsch...
besten dank... es funktioniert einwandfrei

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: last access file

#4 Post by aGerman » 28 Dec 2015 09:04

Good to hear :)
BTW: Based on your variable names I already figured that your mother tongue is German too :wink:

Post Reply