I’m trying to list all the files in a directory and then write that to a text file using a batch file. I think it should be something like
dir / (some flags here) >> files.txt
which will contain a listing like
a.exe
b.exe
c.exe
etc. etc
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have to use the
/bswitch (to write file list only, without header and other informations).Then if you need to list all
.exefiles inc:\windowsthe full command is:Please note that
>>will append the list to the file. Do not forget you can use multiple search patterns, for example:It’ll write all the
.jpgand.pngfiles (only names, without path or any other informations) to the filelist.txt(overwriting the file if it did exist before).If you need to exclude directories you can rely on
/aswitch (to include/exclude items according to an attribute). In your case you want to exclude directories then you have to use-d:Finally do not forget
dircan be used recursively with/sswitch (to list files that match search pattern in the given directory and in all sub-directories) and sorted with/ooption. Usedir /?for more details about that.