Windows - A batch file to list files excluding the subfolders

February 2017




Issue


I need a batch file to list files stored in a folder but without the ones present in the subfolders?

Solution


Try this:
for %%i in (Y:\Files\*.*) do echo %%~ni >> D:\List_of_files.txt

To have a sorted list (alpahabetically).
for %%i in (Y:\Files\*.*) do echo %%~ni | sort >> D:\List_of_files.txt

Related


Published by jak58. Latest update on October 1, 2012 at 10:56 AM by jak58.
This document, titled "Windows - A batch file to list files excluding the subfolders," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).