1

I would like to have an option to get all the files in the folder, just the names (no path and no extension) and sorted by name, in a simple batch file.

I know how to get all the names, but it's not sorted:

for %%i in (*.mxf) do @echo %%~ni >> names.txt

And I know how to get the names sorted, but it comes with the extension:

dir /b /o:n >> names.txt

How can I combine the two commands? Only the names and sorted.

Thanks

2

you can pipe the output to the sort command:

(for %%i in (*.mxf) do @echo %%~ni) | sort /o names.txt

On my system, the files were already sorted by default, so I tested it by reversing the order using the sort option /r.

2

You can put the dir command with applicable sorting options in a for /f loop and redirect the output from there to a file giving you the expected result—this is a way to combine the two as requested.

Script Example

for /f "tokens=*" %%i in ('dir /b /o:n "*.mxf"') do @echo %%~ni >> names.txt

Further Resources

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.