Navigation
Popular content
Active forum topics
Recent comments
|
ForFiles - delete old files, etc.Table of contents for this article IntroductionA few Windows resource kits contained the sometimes very useful tool: forfiles.exe It can be used to process large numbers of files automatically or in a script to delete old files, among other things. You can download the version that is included in Windows 2003 Server here. Its file size is 48,640 bytes. If you are not sure which version to use, use this one. The new version has a strange defect. It throws an error on my computer when it encounters a Google Earth *.kml file. On the other hand it has at least one nicetyit automatically wraps variables like @file in quotes, so you don't have to add escaped quotes (like \") to the command string. An older, much smaller version is still making the rounds, but it has a different switch format, Unix style, using minus signs, rather than slashes. You can download a lean, good version here or here or a somewhat inflated version directly from Microsoft and these or other versions from a few other places. forfiles.exe version 1.1 is 10,512 bytes long. The inflated version from the Microsoft ftp server is 12,048 bytes long. Be wary of longer files, as they may be virus-infected. All versions, if used properly, are suitable to batch delete old files. In the following examples, remove "My ", including the space, if you work on Windows Vista, where these special folders have been renamed not to include "My ". Also replace "Documents and Settings" with "Users" on Vista. Examples for the new version using Windows-style switches (like /c)Prevent batch processing before at least 5 days have passed
Batch file to delete old filesThe following examples show each deleted file name and then wait 8 seconds before actually deleting the file. This allows you to break off with Ctrl + C before the file is actually deleted. Increase the number of seconds if you think that 8 is too little time to decide. The examples require sleep.exe or wait.exe or a similar tool. If you don't have anything like that, you can use ping to a nonexistent address and use its timeout. Delete all files in the standard TEMP folders and all their subfolders after 9 days:
Delete all *.TMP files in the system root (like C:\WINDOWS) that are older than 9 days:
Delete old IIS log files:
Similar examples for the old version using Unix-style switches (like -c)These examples do not show the folder check (@ISDIR==FALSE), but the old version has the ability as well, so you can add that, if you like. Start a batch process only after at least 5 days have passed
Batch file to delete old filesDelete all files in the standard TEMP folders and all their subfolders after 9 days:
Delete all *.TMP files in the system root (like C:\WINDOWS) that are older than 9 days:
Delete old IIS log files:
Please add other good examples. |
User login
Donations If this web site has helped you, please help us too! Recent blog posts
Windows news ticker
Who's new
Who's online
There are currently 0 users and 4 guests online.
hits since 2009-09-09 |
run forfiles from a batch file
Wed, 2008-12-17 14:39 by mpniel
May be it is a bug: I run the forfiles command from windows prompt and it work ok.
When i copy paste the same command into a cmd file it goes into an infinite loop.
Does anyone know the solution?
run forfiles from a batch file
Thu, 2009-05-28 18:43 by Mehrjan
Windows accept space in file names. However, don't put space in your batch file name. I mean use one word as your batch file name!
Why not?
Sat, 2009-05-30 16:06 by admin
Spaces in filenames are normal and should work just fine. Depending on circumstances you may have to enclose the filename in quotes when it is used.
%%
Wed, 2008-12-17 17:47 by admin
In some situations the percent signs have to be duplicated when a command is used in a batch file, for example the percent sign that starts the variable in a for loop command.
I don't know the details off-hand. You have to read it up.