How to delete old temporary files and directories in Windows

Posted by Max | Posted in windows | Posted on 15-04-2009

0

MS Windows has a nice little utility called forfiles. It allows to to process files based on their creation date and other parameters. If you want to clean your temporary directory from old files and folders you can use the following batch file:

Clean.bat:


cd %1
forfiles /p "." /s /c "cmd /c if @isdir==FALSE echo del @file & del @file" /d -9
for /f "tokens=*" %%d in ('dir /ad/b/s ^| sort /R') do rd "%%d"

Now all you have to do is to execute batch script:

Clean.bat C:/My_temp_dir/

If you don’t have forfiles utility installed, you can get it here

Write a comment