Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.



Windows 7: DOS - list files in folders without path

31 Dec 2009   #1

Windows XP
 
 
DOS - list files in folders without path

I have a text file showing files in directories. The text file looks like this:

"C:\folderA\file1.zip"
"C:\folderA\folderB\folderC\file2.zip"
"C:\folderA\folderE\folderX\folderU\file3.zip"

The text file is created by using a batch file with this code segment:
Code:
for /r %inpath% %%g in (*.zip) do echo "%%g" >> textfile.txt
Now, I wish to use the same directory tree and build a second text file with a list of the zip file names contained within, but I want to strip out the folder tree and just list the zip file names. And the zips are on different levels as the above example shows. As part of the solution, I would like to list just the file name and not the extension, like this (note the quotes which are intentional and should appear in the text file):

"file1"
"file2"
"file3"

Thanks for looking and I appreciate any help.

My System SpecsSystem Spec
.

31 Dec 2009   #2

xp, win7
 
 

cmd shell
run command from topdir

for /r %I in (*.zip) do @echo %~nxI
My System SpecsSystem Spec
01 Jan 2010   #3

Windows XP
 
 

oystercatcher

Fantastic. You don't know how many said it can't be done, that I would need to use VB, coupled with windows scripting, and some even suggested excel to parse the file name from the full path.

Your a life saver. Thanks for your expertise. I'm grateful.

This is my final code, run in a batch file at the top level directory:

Code:
for /r %inpath% %%g in (*.zip) do echo "%%~ng" >> test.txt
Tux.
My System SpecsSystem Spec
.


01 Jan 2010   #4

Windows 7 Ultimate 64 bit
 
 

Nice scripts, i'll be adding those to my repository

FYI - If you wanted to to see where the files came from without the path. you may consider something like

tree > "test.txt" /A /F && test.txt
OR
tree "E:\" > "test.txt" /A /F && test.txt
(if you wanted to run it on the E drive for example)
My System SpecsSystem Spec
01 Jan 2010   #5

Windows XP
 
 

Thanks Tim and Happy New Year to all!

I have one more request to make this code really sing. Consider this file list:

fileA.zip
fileB.zip
fileC.ext1
fileC.ext2
fileD.ext1
fileE.ext1

Is it possible to add logic to the batch so the resulting text file would only show:

fileA
fileB
fileC

In other words, even though fileD and fileE are ext1, there is no matching ext2 so they are skipped, or in speaking terms, "find and index all ext1 but only if there is also an ext2 file present with the same name."

Way above my pay grade but hopefully someone here can offer some guidance.

Thanks again,

Tux.
My System SpecsSystem Spec
01 Jan 2010   #6

Windows XP
 
 

ok, here is one failed attempt:

Code:
for /r %inpath% %%a in (*.ext1) do CALL :Subroutine %%g
GOTO:EOF

:Subroutine
if exist "%%g.ext2" do echo "%%~ng"
pause
Or maybe this, but it also doesn't work:

Code:
for /f "tokens=* delims=" %%k in ('dir /s /b *.ext1') do CALL :Subroutine %%g
GOTO:EOF

:Subroutine
if exist "%%g.ext2" do echo "%%~ng"
pause
back to reading...thanks for your help in advance
My System SpecsSystem Spec
01 Jan 2010   #7

Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 

If doesn't have to be a CMD script. It can be done easily in VBScript. Let me know if you would like me to code it and post it.
My System SpecsSystem Spec
01 Jan 2010   #8

Windows XP
 
 

WindowsStar: While I would prefer to see a solution using CMD (for learning purposes mainly) a VB script would be good as well. Also, the app that this is written for is VB, so that might make it easier to integrate it directly into the main app

If we go that route maybe you could offer guidance on switching the small batch to VBS. Code is attached.

Thanks, and I look forward to your response.


Attached Files
File Type: bat darin.bat (1.6 KB, 126 views)
My System SpecsSystem Spec
01 Jan 2010   #9

Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 

I have to run out and do some errands. I will do this later tonight...say 5 hours from now. Just don't want you checking back every 15 min.
My System SpecsSystem Spec
01 Jan 2010   #10

Windows XP
 
 

Thanks a lot. I attached the .bat file and maybe switching it over to VBS would be a good idea for the reasons mentioned in that post.

I'll check in later then. have a good one, Tux
My System SpecsSystem Spec
Reply

 DOS - list files in folders without path





Thread Tools




Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 02:01 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33