Page 1 of 1

What is FORFILES good for

Posted: 03 Jan 2012 07:12
by dbenham
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

Re: What is FORFILES good for

Posted: 03 Jan 2012 07:17
by Squashman
I guess I just use it mostly for the /D option.

Re: What is FORFILES good for

Posted: 03 Jan 2012 07:54
by dbenham
Oooh, I didn't read that option carefully enough. That is useful. Thanks :)

Dave Benham

Re: What is FORFILES good for

Posted: 08 Aug 2013 08:34
by foxidrive
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.

Re: What is FORFILES good for

Posted: 08 Aug 2013 10:07
by Squashman
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.

Re: What is FORFILES good for

Posted: 09 Aug 2013 03:48
by foxidrive
It's a good tool in it's place - it's good to know it's limitations though. :)