1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Batch file to list file names in current Folder.

Discussion in 'Software Development' started by muckmail, Sep 21, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. muckmail

    muckmail Thread Starter

    Joined:
    Jan 2, 2007
    Messages:
    907
    I am trying to write a batch program the list the current directory files that end in *.dwg
    into a file on my C drive.
    I have used the following code:
    dir *.dwg /b >C:FileListing.txt
    start notepad C:FileListing.txt

    This code only gives file names in the current directory.
    I need to have a list of path and file names in the file FileListing.txt
    Is there a way to do that without including subdirectories??

    Thank you,
     
  2. carldickens

    carldickens

    Joined:
    Sep 16, 2010
    Messages:
    18
    try this and see if it gives you what you are asking.

    dir *.dwg /x /s >C:FileListing.txt

    Carl
     
  3. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,783
    I wouldn't use short names.

    This is what I would do.
    Code:
    dir *.dwg /a-d /b /s >C:\FileListing.txt
     
  4. muckmail

    muckmail Thread Starter

    Joined:
    Jan 2, 2007
    Messages:
    907
    I will try the codes a above but the problem with adding /s is that it gives me all Path and files
    in all subdirectories. I only want paths and files in the current directory that I am at.
    Thank you,
     
  5. muckmail

    muckmail Thread Starter

    Joined:
    Jan 2, 2007
    Messages:
    907
    The above codes did not work. I guess because of the /s mentioned in my previous post.
    Any other suggestions.
    Thank you,
     
  6. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,783
    Yeah I totally missed that. Give me a second. I will have a fix for you.
     
  7. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,783
    Code:
    for /F "Tokens=* delims=" %I in ('dir /a-d /b *.txt') do echo %~fI>>C:\filelist.txt
     
  8. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,783
    Did that from the cmd line. Forgot you were doing this in batch. You need to double up on the Percent signs in a batch file.
    Code:
    for /F "Tokens=* delims=" %%I in ('dir /a-d /b *.dwg') do echo %%~fI>>C:\filelist.txt
     
  9. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/951400

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice