Dir command Output into a Text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dubhubb
Posts: 7
Joined: 04 Sep 2009 09:55

Dir command Output into a Text file

#1 Post by dubhubb » 29 Jan 2010 12:56

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!

sweener
Posts: 18
Joined: 06 Jan 2010 13:00
Location: Indianapolis, IN

Re: Dir command Output into a Text file

#2 Post by sweener » 29 Jan 2010 13:16

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?

dubhubb
Posts: 7
Joined: 04 Sep 2009 09:55

Re: Dir command Output into a Text file

#3 Post by dubhubb » 29 Jan 2010 14:01

I think that did the trick.

Thanks so much! :mrgreen:

Post Reply