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
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.
Windows 10:
open cmd
change directory where you want to create text file(movie_list.txt) for the folder (d:\videos\movies)
type following command
d:\videos\movies> dir /b /a-d > movie_list.txt
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
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
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.
dir /s/d/a:-d "folderpath*.*" > file.txt
And, lose the /s if you do not need files from subfolders