Batch File; List files in directory, only filenames?

前端 未结 8 1378
我在风中等你
我在风中等你 2021-01-29 22:07

This is probably a very simple question, but I\'m having trouble with it. Basically, I am trying to write a Batch File and I need it to list all the files in a certain directory

相关标签:
8条回答
  • 2021-01-29 22:18

    If you need the subdirectories too you need a "dir" command and a "For" command

    dir /b /s DIRECTORY\*.* > list1.txt
    
    for /f "tokens=*" %%A in (list1.txt) do echo %%~nxA >> list.txt
    
    del list1.txt
    

    put your root directory in dir command. It will create a list1.txt with full path names and then a list.txt with only the file names.

    0 讨论(0)
  • 2021-01-29 22:18

    Windows 10:

    1. open cmd

    2. change directory where you want to create text file(movie_list.txt) for the folder (d:\videos\movies)

    3. type following command

      d:\videos\movies> dir /b /a-d > movie_list.txt

    0 讨论(0)
  • 2021-01-29 22:20

    1.Open notepad

    2.Create new file

    3.type bellow line

    dir /b > fileslist.txt
    

    4.Save "list.bat"

    Thats it. now you can copy & paste this "list.bat" file any of your folder location and double click it, it will create a "fileslist.txt" along with that directory folder and file name list.

    Sample Output:

    Note: If you want create file name list along with sub folder, then you can create batch file with bellow code.

    dir /b /s > fileslist.txt
    
    0 讨论(0)
  • 2021-01-29 22:22

    create a batch-file with the following code:

    dir %1 /b /a-d > list.txt
    

    Then drag & drop a directory on it and the files inside the directory will be listed in list.txt

    0 讨论(0)
  • 2021-01-29 22:26

    The full command is:

    dir /b /a-d
    

    Let me break it up;

    Basically the /b is what you look for.

    /a-d will exclude the directory names.


    For more information see dir /? for other arguments that you can use with the dir command.

    0 讨论(0)
  • 2021-01-29 22:26

    dir /s/d/a:-d "folderpath*.*" > file.txt

    And, lose the /s if you do not need files from subfolders

    0 讨论(0)
提交回复
热议问题