Listing files using dir /s

Posted on 2008-11-06
Last Modified: 2012-05-05
This question is more out of curiosity, mainly because I could not make it work.  I am sure there is a batch file to do this, but I wonder if there is a command line command to; display only the file names under each subdirectory.  It would be a: dir /b  but once I add /s then the subdirectory path is listed for each file.
Question by:chima
    LVL 38

    Accepted Solution

    Paste the script below into a text file with a .cmd extension.  Customize the value of the folder variable with the location of the folder to search under.  Running the script will echo just the filenames.

    @echo off
    set folder=c:\files
    for /F "tokens=*" %%G in ('dir "%folder%" /A:-D /B /S') do echo %%~nxG

    Open in new window

    LVL 21

    Assisted Solution

    dir/s/w will give you only the file names

    Author Closing Comment

    Shift-3, I will try this later on in the day.  silemone, thank you I appreciate your response.
    LVL 21

    Expert Comment

    good luck


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now