Windows - A batch file to list files excluding the subfolders

December 2016




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 :

This document entitled « Windows - A batch file to list files excluding the subfolders » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.