Wednesday 21 September 2011

DOS script which outputs directory contents into a txt file

This simple batch file prints out (recursively, including subdirectories) the content of the current directory into a text file:

list_all_files.bat:
dir /b /s * >temp.txt

dir * lists the content of the current directory. /b switch makes it to use bare format (report does not include heading information or summary). /s instructs it to use recursion. >temp.txt instructs it to output report to temp.txt file.

After running it, this is the content of temp.txt:
C:\test\list_all_files.bat
C:\test\mydir
C:\test\temp.txt
C:\test\mydir\a.txt

Links and references:
Microsoft DOS dir command

No comments: