DOS - list files in folders without path

Page 1 of 2 12 LastLast

  1. Posts : 12
    Windows XP
       #1

    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 Computer


  2. Posts : 10
    xp, win7
       #2

    cmd shell
    run command from topdir

    for /r %I in (*.zip) do @echo %~nxI
      My Computer


  3. Posts : 12
    Windows XP
    Thread Starter
       #3

    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.
    Last edited by tuxalot; 01 Jan 2010 at 02:45. Reason: more 'splainin to do...
      My Computer


  4. Posts : 1,020
    Windows 7 Ultimate 64 bit
       #4

    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 Computer


  5. Posts : 12
    Windows XP
    Thread Starter
       #5

    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 Computer


  6. Posts : 12
    Windows XP
    Thread Starter
       #6

    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 Computer


  7. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #7

    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 Computer


  8. Posts : 12
    Windows XP
    Thread Starter
       #8

    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.
    DOS - list files in folders without path Attached Files
      My Computer


  9. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #9

    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 Computer


  10. Posts : 12
    Windows XP
    Thread Starter
       #10

    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 Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About 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 18:51.
Find Us