DOS command to get all files in a directory

I am trying to extract a list of all file names and extensions on a file share and all I have been able to extract the root folder.  What am I missing here?

FOR %%i IN \\DIR\data\jgh\ Incoming\*.* DO echo %%i >> List_Incoming.txt
JGH5Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
It's easier than that.  Do this:

dir /b /s /a-d "\\DIR\data\jgh\Incoming\*.*" >>List_Incoming.txt

Open in new window

~bp
0
JohnBusiness Consultant (Owner)Commented:
To get subfolders, a command like DIR  /s works. So put a /s after *.*  . /s is the subfolder switch .

... Thinkpads_User
0
JGH5Author Commented:
I am changing the extension to a .bat file.  Which folder should I execute the .bat command from? The root or within the directory?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Bill PrewCommented:
If you did want to use a FOR, you need the /R option to drill into subfolders, like:

for /R "\\DIR\data\jgh\Incoming" %%A in (*.*) do echo %%A>> List_Incoming.txt

Open in new window

and if you just want the file base name and extension, without the path you could do:

for /R "\\DIR\data\jgh\Incoming" %%A in (*.*) do echo %%~nxA>> List_Incoming.txt

Open in new window

~bp
0
Bill PrewCommented:
==> I am changing the extension to a .bat file.  Which folder should I execute the .bat command from?
==> The root or within the directory?

Since you have the full path to the folder to list the files in, it doesn't matter where the BAT file resides, or what the current directory is when you run it.  Do keep in mind though that since you haven't fully qualified the output file path (it's just the file name), then it will be created in the current folder when the BAT script is run.

~bp
0
ReneGeCommented:
@JGH5:
Since you quoted "able to extract the root folder." I was just wondering if you needed to include the sub-directories and there content?

Cheers
0
JGH5Author Commented:
I found a solution:
 
FOR /r /w %%a IN (*.*) DO echo %%a >> File_List.txt

Pause

Does anyone know how to include the Date Modified for each file in the sub directories?
0
ReneGeCommented:
FOR /r /w %%a IN (*.*) DO echo [%%~ta] %%a >> File_List.txt
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ReneGeCommented:
@JGH5:
My answer is more %%~ta then the command line itself, because I am not familliar with the /w, in the FOR loop.

Billprew would know though.

Cheers
0
Bill PrewCommented:
==> I found a solution:

Isn't that essentially what I proposed?

As Rene indicates, %%~ta will get you the date modified.

~bp
0
Bill PrewCommented:
==> FOR /r /w %%a IN (*.*) DO echo %%a >> File_List.txt

On my system, Windows 7, that syntax is not valid, the /W is not accepted as an option on the FOR.

~bp
0
ReneGeCommented:
I fired up a fully updated XP Pro virtual PC and the same for me. The /W is not accepted as an option on the FOR.

Just currious, where did you get this info? Does it work for you?

Cheers,
Rene
0
JGH5Author Commented:
Still working on getting this to work. I have WIN 7 as well and still tweaking.
0
Bill PrewCommented:
Was there something that my first two posts in this thread didn't address, those should have been working solutions for the filename list.  And just adding the date to the second one using a FOR should be easy, such as:

for /R "\\DIR\data\jgh\Incoming" %%A in (*.*) do echo %%~tA, %%A>> List_Incoming.txt

Open in new window

~bp
0
ReneGeCommented:
Glad I could help and thanks for the points.

Cheers,
Rene
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.