File list using DIR

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
highandwild
Posts: 2
Joined: 02 Nov 2013 07:41

File list using DIR

#1 Post by highandwild » 02 Nov 2013 08:14

I'm trying to output, to a text file, a list of files in a folder and its sub-folders in a one line per file format with
date, size and folder name.

I've fiddled around with various switches but I have not got there yet.

Any ideas anybody?

Thanks

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: File list using DIR

#2 Post by aGerman » 02 Nov 2013 08:57

Run DIR in a FOR /F loop and use the modifiers of FOR variables to expand them to the data you need.

Code: Select all

for /f "delims=" %%i in ('dir /a /b /s "c:\your\folder"') do echo "%%~nxi" %%~ti %%~zi "%%~dpi"

Regards
aGerman

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: File list using DIR

#3 Post by foxidrive » 02 Nov 2013 09:09

+1 but use /a-d instead of /a in the dir command, to eliminate folders.

highandwild
Posts: 2
Joined: 02 Nov 2013 07:41

Re: File list using DIR

#4 Post by highandwild » 02 Nov 2013 10:52

Thanks for this.

Where do I insert the file name in which I would llke the listing saved?

Thanks

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: File list using DIR

#5 Post by Squashman » 02 Nov 2013 12:46

highandwild wrote:Thanks for this.

Where do I insert the file name in which I would llke the listing saved?

Thanks

Redirect the output of aGerman's code to a text file.
You can read about redirecting output here.
http://www.robvanderwoude.com/redirection.php

shayanjameel08
Posts: 10
Joined: 21 Nov 2013 01:07

Re: File list using DIR

#6 Post by shayanjameel08 » 27 Nov 2013 23:54

The only other thing I saw was "FindFileFirst", but I can't seem to get that to work at all.
So, my question is, how do I get the names of folders using "Dir()"?

Post Reply