Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forfiles help

Status
Not open for further replies.

westwood01

Technical User
Dec 28, 2003
41
US
Hello all.

Looking for help using the forfiles command.

Goal: To find and rename the 'oldest file only' in a given directory. I have the find and rename part down, but am having trouble identiying the oldest file by date/time.

I imagine I will have to use the @FTIME and/or @FDATE. Thanks in advance for your help.
 
never heard of the forfiles command or @FTIME, are you sure you have the right language?
 
Sounds like perl?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I assume you meant you never heard of forfiles for vb. I also posted my question to the win2000 server forum. Sorry if this post was misplaced.
 
Its actually a windows resource utility that requires some coding syntax. I just figured I would post it to the vb forum in the hopes someone would recognize it.
 
i am sure you could combine on for the file folder loop posts with an array/dic object bubble sort posts to get what you want....(lord knows what bubble means?)
 
Hello westwood01,

If we might not be able to answer to your satisfaction. Then, you can post to win2000 or winxp desktop forum.

To answer to your question, try pipe the output to sort then redirect to a text file. Use @FDATE. For instance, like this.
[tt]
forfiles -s -pd:\ -m*.* -c"%comspec% /c echo @FDATE @PATH\@FILE" | sort > c:\sortoutput.txt[/tt]

The sorted result will help you to determine what to delete.

regards - tsuji
 
Hello tsuji, thank you for your reply. Can you elaborate a bit more on your sorting example? I can do the sort, but what am I looking for in the sortoutput.txt? I already know I want to rename the oldest file only. Are you suggesting additional code to read the .txt?

Below is where I'm at now. This works well, but it is finding and renaming the file based on alpha/numeric order, not by timestamp. I would like it to find and rename by oldest timestamp regardless of filename.

forfiles -p"P:\DATA\Corporate\Scripts\rename" -v -ma*.xml -d- -c"cmd /c ren @FILE expected.xml

Thanks again. I also posted this to the XP desktop forum for more exposure.
 
Workaround for forefiles lack of renaming by 'oldest' timestamp.

forfiles -p"P:\DATA\Corporate\Scripts\rename" -v -mauth*.xml -c"cmd /c ren @FILE auth@FDATE-@FTIME.xml
forfiles -p"P:\DATA\Corporate\Scripts\rename" -v -mauth*.xml -c"cmd /c ren @FILE process_me_first_im_old_auth.xml

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top