Thursday, January 15, 2009

How to get a list of files and subdirectories in a directory using DOS command.

**********************************************
Requirement :-
To get a list of files and subdirectories in a directory using DOS command.

Logic :-
Use DIR command under command prompt to get a list of files and subdirectories in a directory.
If you want to :-
1.Lists the files in the directory that you are in and all sub directories after that directory, if you are at root "C:\>" and type this command this will list to you every file and directory on the C: drive of the computer.
USE : - dir /s
2.If the directory has a lot of files and you cannot read all the files as they scroll by, you can use this command and it will display all files one page at a time.
USE : - dir /p
3.List the files in alphabetical order by the names of the files.
USE : - dir /on
4.Take the output of dir and re-routes it to the file myfile.txt instead of outputting it to the screen
USE : - dir > myfile.txt
5.If you don't need the info on the date / time and other information on the files, you can use this command to list just the files and directories going horizontally, taking as little as space needed.
USE : - dir /w

Note :- > myfile.txt suffix can be used along with any command to re-route the DIR output into a text file.

Example :- To get all the file names in D:\Test\List

USE Command :- dir D:\Test\List >make_list.txt

The generated text file will be available in C:\Documents and Settings\user_name.

If you want the file in a predetermined location specify the path as below.

USE Command :- dir D:\Test\List >D:\Test\List\make_list.txt

******************* Kumargs *******************

No comments:

Post a Comment