Solved

WINDOWS XP PRO SP2 findfiles command

Posted on 2008-10-06
8
1,595 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
Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

 

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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 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