I need to run a command in a cmd window (in XP) that will return results about the files in a given directory. Fortunuately any given directory will not contain more than 9999 files, so if I set the row buffer to 9999 then I am okay. However, I need to run this command on about 600 directories! I would appreciate any suggestions on how to tackle the problem.

I was thinking maybe a batch file that would open a cmd prompt, set the buffer to 9999 rows, run the command, leave the window open, and while the first window is running then open a new window and repeat the process.

Of course, if I could buffer or somehow return the results of more than 9999 files then that would be even better.

Thank you in advance, Andrew


You can store the screen output in a text file by using > or >>. To use it, enter the command as you normally would but at the end you add one or two greater thans and then the name of the file you want to output to, like so: dir c:\users /s > c:\list.txt Using a single > will always create a new file, overwriting any existing files with that name. Using two >> will create the file if it doesn't exist, but will append to existing files. This can be really helpful for logging batch files, because you can put >> file.txt after every line and it would output all the screen output to the same file so you can review it in order. Keep in mind that using this method will prevent the output on the screen, because it redirects it to the file. You can usually open the file to review it even while it is being created (just make sure not to lock it or save to it).

Sample batch file with some logging:

@echo off
SET DATENOW=%date:~-4,4%-%date:~-10,2%-%date:~-7,2%
SET TIMENOW=%time:~-11,2%.%time:~-8,2%.%time:~-5,2%
SET FILENAME="C:\Logs\Finance Batch %DATENOW% [%TIMENOW%].log"

if not exist "C:\Logs" md C:\Logs

ECHO Clearing current folder... [%time%] >> %FILENAME%
if exist "C:\Files" rd "C:\Files" /s/q >> %FILENAME%
if not exist "C:\Files" md "C:\Files" >> %FILENAME%

ECHO Copying data from SHAREDOCS... [%time%] >> %FILENAME%
xcopy "\\domain.local\sharedocs\*.*" "C:\Files" /EXCLUDE:exclist.txt /e /c /z /k >> %FILENAME%

|improve this answer|||||
  • +1. If it grows too large, I'd recommend searching for a large text file viewer, as large files can make Notepad cough – Canadian Luke Jul 24 '12 at 16:14
  • Whoohoo! Thank you! But now I have a follow-up question... – Andrew Jul 24 '12 at 16:19
  • So my first command is: c:\Myapp\trigger \\this\that\another\0\0*.bin >>c:\Myapp\output.txt This is working great. Thank you! But the next directory is: \\this\that\another\0\1\ and the next is: \\this\that\another\0\2\ and so on up to 278 (then I switch paths entirely) How can I organize it so I don't have to run this 278 times? Also, how can I tell when the run is complete, as the screen no longer tells me? Thanks again, Andrew – Andrew Jul 24 '12 at 16:23
  • The run is complete when the command stops running, it won't return before it's done. The first followup seems more like something you should ask in a new question, it doesn't seem closely related to this one, unless I'm missing something? – dsolimano Jul 24 '12 at 16:27
  • Thank you. I will ask the follow up in a new question, if needed. I think with the information you have given me that I my be able to solve the rest myself (fingers crossed). Thanks again, Andrew – Andrew Jul 24 '12 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.