What is FORFILES good for

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

What is FORFILES good for

#1 Post by dbenham » 03 Jan 2012 07:12

Does anyone see any inherent benefits to using FORFILES instead of some flavor of a FOR loop? FORFILES seems awkward and potentially slow to me since it spawns a new CMD for each path found.

The only potential benefits I see is it can give you a relative path (@RELPATH), it can differentiate between a file and a folder (@ISDIR), and it can give you the file last modified time including seconds (@FTIME).


Dave Benham

Squashman
Expert
Posts: 4479
Joined: 23 Dec 2011 13:59

Re: What is FORFILES good for

#2 Post by Squashman » 03 Jan 2012 07:17

I guess I just use it mostly for the /D option.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: What is FORFILES good for

#3 Post by dbenham » 03 Jan 2012 07:54

Oooh, I didn't read that option carefully enough. That is useful. Thanks :)

Dave Benham

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: What is FORFILES good for

#4 Post by foxidrive » 08 Aug 2013 08:34

Adding to an old thread

A post on Stack Overflow noted that Forfiles @fsize doesn't work with filesizes over 10 digits.
But it's even worse than that - it corrupts the digits that are reported.

Using this command it gives the output below:

Code: Select all

@forfiles /p . /m c*.7z /c "cmd /c echo @fsize @fname @fdate,@ftime"


7080760325 "Coverse" 3/12/2012,22:36:19

and this is what DIR reports ( Win 8 )

03/12/2012 22:36 19,965,662,213 Coverse.7z


Pretty nasty.

Squashman
Expert
Posts: 4479
Joined: 23 Dec 2011 13:59

Re: What is FORFILES good for

#5 Post by Squashman » 08 Aug 2013 10:07

Well I still like the FORFILES trick to print just about any character. Can't remember if that was Dave who brought that up as well.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: What is FORFILES good for

#6 Post by foxidrive » 09 Aug 2013 03:48

It's a good tool in it's place - it's good to know it's limitations though. :)

Post Reply