$f D:\USR\DEFAULT\SOMETHING.TXT $n SOMETHING.TXT $b SOMETHING $e .TXT $p D:\USR\DEFAULT\ $d \USR\DEFAULT\ $r DEFAULT\ (path relative to current directory) $v D:
-s: recurse into subdirectories. -n: noshell (suppresses use of shell specified by COMSPEC) -c: chdir to $p before executing Command. -e: echo Command to console before executing it. -p: pause for confirmation before executing Command. -8: use DOS (8.3) filenames in macro expansions. -m<char>: designate a character other than '$' to start macros. -x<spec>: exclude files matching spec from Filespec.
ForEachFile *.c -s fc $n j:$r$nFor each file with a .c extension in the current directory and all its subdirectories, this command runs the Win95 FC.EXE utility to compare the file with a file of the same name and in the same relative location on drive J:. This is handy because, although FC supports wildcard filespecs, it does not recurse into subdirectories.
ForEachFile "*.c *.h *.cpp" comptime -v $f \\SomeServer\sharename\src\$nThis command uses the utility COMPTIME.EXE (included with ForEachFile.exe in PRESENTS.ZIP) to show any timestamp differences between source files in the current directory and same-named sources on a server specified with a UNC name.
ForEachFile "/ar-d *.?" -s fc $f j:$d$fThis command searches for read-only non-directory files with single-character extensions in or under the current directory and uses FC.EXE to compare them with same-named files in a parallel location on drive J:. Note that the "/ar-d" is part of the filespec, not a ForEachFile switch.
ForEachFile *.txt -s start notepad $fThis command loads each .txt file in the current directory or any of its subdirectories into a separate instance of the Win95 notepad applet.
ForEachFile *.txt -s copy $f c:\temp\$b.bakThis command copies all .txt files in or under the current directory to the c:\temp directory and changes their extensions to .bak.
ForEachFile "*.txt *.lst" -s -8 list $r$nThe -s (recurse into subdirectories) and -8 (use 8.3 filenames) arguments in this command make the shareware LIST utility more useful by solving its inability to handle long file and directory names, as well as its lack of support for directory recursion.
ForEachFile "*.tmp *.bak tmp*.*" -s -e move $f c:\tempThis command searches the current directory and all its subdirectories for files ending in .tmp or .bak, and for files beginning with "tmp", and moves them to c:\temp. The -e argument causes it to echo each command as it is executed so you can see what is happening.
ForEachFile "/ad *.?" -s echo $fThis command recurses through all subdirectories of the current directory and displays their names.
ForEachFile is updated occasionally in http://www.teleport.com/~brecheen.
Written by Cole Brecheen (brecheen@teleport.com), November 1995.