Page 1 of 1

Dir command Output into a Text file

Posted: 29 Jan 2010 12:56
by dubhubb
I'm having trouble getting files names to be outputted into a text file. As of now I can only get the directory names to be outputted and not the files within. Right now I have:

FOR /D %%I IN ("\\server\data\jan-2010\*") DO dir /b "%%I" >> "%userprofile%\desktop\output.txt"

The above code just copies the directory names within the "jan-2010" folder. I need it to copy the file names within those directories into the text file. I'm stumped.


Any help would be appreciated.

Thanks!

Re: Dir command Output into a Text file

Posted: 29 Jan 2010 13:16
by sweener
You could try something like this:

Code: Select all

SET directory=\\server\data\jan-2010
FOR /F "tokens=*" %%I in ('dir %directory% /ad /b') DO dir "%directory%\%%I" /a-d /b >> dir.txt


You could even play with the /s switch in the dir command to parse through layers of subfolders. Is this any help?

Re: Dir command Output into a Text file

Posted: 29 Jan 2010 14:01
by dubhubb
I think that did the trick.

Thanks so much! :mrgreen: