Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WINDOWS XP PRO SP2 findfiles command

Posted on 2008-10-06
8
Medium Priority
?
1,600 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

604 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