Batch file; List of files in a directory, only file names?

This is probably a very simple question, but I have problems with it. Basically, I'm trying to write a batch file, and I need it to display all the files in a specific directory. The dir command will do this, but also provide a ton of other information; I want it to display ONLY file names and exclude something else.

I want the result to look like this:

 file1.txt file2.txt file3.txt 

Thanks in advance!

+96
batch-file
Apr 22 '14 at 19:56
source share
7 answers

Full team:

 dir /b /ad 

Let me figure it out

Basically, /b is what you are looking for.

/ad will exclude directory names.




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

+192
Apr 22 '14 at 19:57
source share

You can also try the following:

 for %%a in (*) do echo %%a 

Using the for loop, you can echo delete all the file names of the current directory.

+23
Apr 22 '14 at 20:06
source share

If you also need subdirectories, you need the "dir" command and the "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 the dir command. It will create list1.txt with full paths and then list.txt with just the file names.

+5
May 03 '18 at 10:14
source share

1.Open notebook

2. Create a new file

3. type below line

 dir /b > fileslist.txt 

4. Save " list.bat "

This is it. Now you can copy and paste this file “ list.bat ” to any place in your folder and double click on it, it will create “ fileslist.txt ” along with this folder and a list of file names.

Output Example: enter image description here

Note. If you want to create a list of file names with a subfolder, then you can create a batch file with the code below.

 dir /b /s > fileslist.txt 
+3
Jul 17 '18 at 5:32
source share

Windows 10:

  1. open cmd

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

  3. enter the following command

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

+2
Mar 24 '18 at 3:36
source share

create a batch file with the following code:

 dir %1 /b /ad > list.txt 

Then drag the directory onto it and the files inside the directory will be listed in list.txt

+1
May 17 '19 at 14:42
source share

dir / s / d / a: -d "file.txt

And lose / s if you don't need files from subfolders

0
Aug 07 '19 at 15:53
source share



All Articles