forfiles command


Working on forfiles command so we can create a batch file to delete automatically files  older than 60 days on one of our clients

There is more than one version of forfiles, one for Windows 2000 and another one for Windows Server 2003.  The Windows 2000 version uses dashes (“-“) before the parameters ; the Windows Server 2003 uses slashes (“/”). The Windows 2003 version did not work on Windows XP, so more tests need to be done to find out which version works for Windows XP. 

This is the string that worked on a Windows Server 2003 test:

echo To list all of the batch files on drive C, type:
forfiles /p c:\  /m *.bat /c “cmd /c echo @file is a batch file”
echo.
echo To list all of the files in the current directory that are at least one year old, type:
forfiles  /m *.* /d -365 /c “cmd /c echo @file is at least one year old.”
echo.
echo To display the text “File is outdated” for each of the files in the current directory that are older than January 1, 2007, type
forfiles  /m *.* /d -01/01/2007 /c “cmd /c echo @file is outdated.” 
echo.
To list the file name extensions of all the files in the current directory in column format, and add a tab before the extension, type:
echo.
forfiles  /m *.* /c “cmd /c echo The extension of @file is 0x09@ext” 
echo.
echo To list all of the directories on drive C, type:
forfiles /p c:\  /m *.* /c “cmd /c if @isdir==true echo @file is a directory”

echo To list all of the batch files on drive C, type:

forfiles /p c:\  /m *.bat /c “cmd /c echo @file is a batch file”

echo.

echo To list all of the files in the current directory that are at least one year old, type:

forfiles  /m *.* /d -365 /c “cmd /c echo @file is at least one year old.”

echo.

echo To display the text “File is outdated” for each of the files in the current directory that are older than January 1, 2007, type

forfiles  /m *.* /d -01/01/2007 /c “cmd /c echo @file is outdated.” 

echo.

To list the file name extensions of all the files in the current directory in column format, and add a tab before the extension, type:

echo.

forfiles  /m *.* /c “cmd /c echo The extension of @file is 0x09@ext” 

echo.

echo To list all of the directories on drive C, type:

forfiles /p c:\  /m *.* /c “cmd /c if @isdir==true echo @file is a directory”

*** jp

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: