get list of files in a folder including subfo

July 26, 2010 at 06:21:35
Specs: Windows XP
Executing dir "C:\folder\*" /s/b, we get the following:
C:\folder\file1.txt
C:\folder\file2.exe
C:\folder\file3.zip
C:\folder\file4.doc
C:\folder\file5.dll
C:\folder\folder2\somefile.txt
C:\folder\folder2\somefile.exe
C:\folder\folder3\somefile.zip
C:\folder\folder3\somefile.doc
C:\folder\folder3\anotherfolder\anotherfile.dll

But I need only the pathnames of the files, not the full pathnames of all the files in the folder as well as all the subfolders.


See More: get list of files in a folder including subfo

Report •

#1
July 26, 2010 at 10:36:12
Please reply.

Report •

#2
July 26, 2010 at 13:48:18
Not quite sure what your looking for, but try this to give you only the directory names?

C:\> dir /a:d /s C:

MIKE

http://www.skeptic.com/


Report •

#3
July 26, 2010 at 19:13:30
download sed for windows, then do this

dir "C:\folder\*" /s/b | sed "s/\\.[^\\]*$//"

GNU win32 packages | Gawk


Report •

Related Solutions

#4
July 26, 2010 at 19:23:05
Unreliable*, quick and dirty:

dir "C:\folder\*." /s/b

*Unreliable because it will also list files without extensions.

When your only tool is a hammer, every problem looks like a nail.


Report •

#5
July 27, 2010 at 02:54:42
Thank you guys for your replies.
But I need the output as following:
\file1.txt
\file2.exe
\file3.zip
\file4.doc
\file5.dll
\folder2\somefile.txt
\folder2\somefile.exe
\folder3\somefile.zip
\folder3\somefile.doc
\folder3\anotherfolder\anotherfile.dll

Report •

#6
July 27, 2010 at 07:59:08
I need only the pathnames of the files

Which files do you need?

not the full pathnames of all the files in the folder as well as all the subfolders.

Are they a group of specifically named files?
Do they have a unique extension?
Are they in a specific sub-directory?

Like I said before, “not sure what it is your looking for.”

MIKE

http://www.skeptic.com/


Report •

#7
July 27, 2010 at 08:01:37
Do you want the pathnames minus the C:\

You get:
C:\folder\file1.txt

You want:
\folder\file1.txt

Is this correct?

MIKE

http://www.skeptic.com/


Report •

#8
July 27, 2010 at 11:24:57
@mmcconaghy
I want only the file list of a folder, including that of the subfolders.
say that the folder for which I am looking to get the list is "C:/folder"and it has following content:
1.txt
2.txt
subfolder1\1.txt
subfolder2\2.txt
subfolder2\sub-subfolder1\1.txt

I want a list as above not as following which is given by dir "c:\folder" \b \s:
C:\folder\1.txt
C:\folder\2.txt
C:\folder\subfolder1\1.txt
C:\folder\subfolder2\2.txt
C:\folder\subfolder2\sub-subfolder1\1.txt

where as I want output to be the following:
1.txt
2.txt
subfolder1\1.txt
subfolder2\2.txt
subfolder2\sub-subfolder1\1.txt


Report •

#9
July 27, 2010 at 20:31:35
Sorry, but I do not have the batch skills for this problem.
Hopefully, someone more adept at batch programming will have a solution.

MIKE

http://www.skeptic.com/


Report •

#10
July 28, 2010 at 10:31:19
Hope somebody replies soon with an answer. Anyway thanks man. :)

Report •

#11
July 28, 2010 at 11:12:13
If your really desperate,
then a really round about way is to do a:
dir "c:\folder" \b \s >> filename.txt

Then open the filename.txt file in Word and do a
Search & replace
Replace the string: C:\folder\
With nothing.

Not really efficient, but it will get the job done.

MIKE

http://www.skeptic.com/


Report •

#12
July 28, 2010 at 15:09:12
I am actually doing the same thing "dir "c:\folder" \b \s >> filename.txt" but the output in the file is to be as I said above. This line of script is a part of a build script, and should only use DOS commands. Somewhere I had read about using Find and For, but I couldn't use it properly.

Thanks a lot again for replying mmcconaghy.


Report •

#13
July 28, 2010 at 15:13:57
Hey mmcconaghy could you come to the Bat login decusion because you guys got tons of posts in very little time

Report •

#14
July 28, 2010 at 20:49:42
Try this, it's the best I can come up with:

FOR /F "tokens=2* delims=\" %%G IN ('dir /b /s') DO (
ECHO %%G %%H >> filename.txt)

Hopefully someone with a bit more knowledge will point out any errors.

MIKE

http://www.skeptic.com/


Report •

#15
July 30, 2010 at 17:39:41
Thanks man :) that did help :)

Report •

Ask Question