JGH5
asked on
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
FOR %%i IN \\DIR\data\jgh\ Incoming\*.* DO echo %%i >> List_Incoming.txt
To get subfolders, a command like DIR /s works. So put a /s after *.* . /s is the subfolder switch .
... Thinkpads_User
... Thinkpads_User
ASKER
I am changing the extension to a .bat file. Which folder should I execute the .bat command from? The root or within the directory?
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
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
~bp
==> 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
==> 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
@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
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
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@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
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
==> I found a solution:
Isn't that essentially what I proposed?
As Rene indicates, %%~ta will get you the date modified.
~bp
Isn't that essentially what I proposed?
As Rene indicates, %%~ta will get you the date modified.
~bp
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Just currious, where did you get this info? Does it work for you?
Cheers,
Rene
ASKER
Still working on getting this to work. I have WIN 7 as well and still tweaking.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad I could help and thanks for the points.
Cheers,
Rene
Cheers,
Rene
Open in new window
~bp