Solved

WINDOWS XP PRO SP2 findfiles command

Posted on 2008-10-06
8
1,592 Views
Last Modified: 2008-10-11
When I run the following code

Forfiles -p. -s -m*.* -d-1 -c "Cmd /C del @FILE"

I get an error

can't execute (error 2)

I am trying to create a batch file that at startup will delete all files older than today in 2 directories.  This code, as I test, only works on the current directory

Any thoughts are greatly appreciated.
0
Comment
Question by:bschiel
  • 4
  • 4
8 Comments
 

Expert Comment

by:corstiaan_haaij
ID: 22653600
You can build the following batch job:

forfiles /p "drive:\directory" /s /m *.* /d -1 /c "cmd /c del @file"
forfiles /p "drive:\other directory" /s /m *.* /d -1 /c "cmd /c del @file"
0
 

Author Comment

by:bschiel
ID: 22653710
That is the eventual goal, but I am trying to find out why the first code is not working
0
 

Expert Comment

by:corstiaan_haaij
ID: 22654153
you have to specify a directory after the /p and add a space after each parameter
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

Author Comment

by:bschiel
ID: 22654198
/p . defines the directory as the CURRENT directory

When I add spacing I get
C:\>Forfiles -p . -s -m *.* -d -1 -c "Cmd /C del @FILE"
FORFILES v 1.1 - by Emmanuel Boersma - 4/98


Syntax : FORFILES [-pPath] [-mSearch Mask] [-ccommand] [-dDDMMYY] [-s]

 -pPath             Path where to start searching
 -mSearch Mask      Search files according to <Search Mask>
 -cCommand          Command to execute on each file(s)
 -d[+|-][DDMMYY|DD] Select files with date >= or <=DDMMYY (UTC)
                    or files having date >= or <= (current date - DD days)
 -s                 Recurse directories
 -v                 Verbose mode

The following variables can be used in Command :
 @FILE, @PATH, @RELPATH, @ISDIR, @FSIZE, @FDATE, @FTIME


Default : <Directory : .> <Search Mask : *.*>  <Command : "CMD /C Echo @FILE">
Examples :
FORFILES -pc:\ -s -m*.BAT -c"CMD /C Echo @FILE is a batch file"
FORFILES -pc:\ -s -m*.* -c"CMD /C if @ISDIR==TRUE echo @FILE is a directory"
FORFILES -pc:\ -s -m*.* -d-100 -c"CMD /C Echo @FILE : date >= 100 days"
FORFILES -pc:\ -s -m*.* -d-010193 -c"CMD /C Echo @FILE is quite old!"
0
 

Expert Comment

by:corstiaan_haaij
ID: 22654336
Which error will be shown?
When i run this batch no error will appear!
0
 

Author Comment

by:bschiel
ID: 22654392
When I run the original code I get what I originally posted.

When I run as you suggested, I get what I just posted.  Not sure what additional info you want
0
 

Accepted Solution

by:
bschiel earned 0 total points
ID: 22654724
Solved my own problem.....

I was using an older version of FORFILES that did not work correctly with XP.  Pulled a newer version from my 2K3 server and it works as it supposed too.
0
 

Expert Comment

by:corstiaan_haaij
ID: 22654742
okay great
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question