fortypoundhead.com

DIR

Posted On 2005-11-1 by FortyPoundHead
Keywords: Command Reference
Tags: Windows Commandline Windows
Views: 1704


DIR

Display a list of files and subfolders



syntax

      DIR [pathname(s)] [display_format] [file_attributes] [sorted] [time] [options]

key


   [pathname] The drive, folder, and/or files to display, this can include wildcards:



      *   Match any characters

   ?   Match any ONE character  



[display_format]



   /P   Pause after each screen of data.

   /W   Wide List format, sorted horizontally.

   /D   Wide List format, sorted by vertical column.

  

[file_attributes]



   /A:    /A:D  Folder         /A:-D  NOT Folder

   /A:R  Read-only       /A:-R  NOT Read-only

   /A:H  Hidden         /A:-H  NOT Hidden

   /A:A  Archive         /A:-A  NOT Archive

   /A    Show all files  



several attributes may be combined e.g.: /A:HD-R  



[sorted]  



Sorted by /O:  



   /O:N   Name                  /O:-N   Name  

   /O:S   file Size             /O:-S   file Size

   /O:E   file Extension        /O:-E   file Extension  

   /O:D   Date & time           /O:-D   Date & time

   /O:G   Group folders first   /O:-G   Group folders last



   several attributes may be combined e.g. /O:GEN  



[time]

  

   /T:  the time field to display & use for sorting

   /T:C   Creation

   /T:A   Last Access

   /T:W   Last Written (default)  



[options]



   /S     include all subfolders.

   /B     Bare format (no heading information or summary).

   /L     use Lowercase.

   /Q     Display the owner of the file.

   /N     long list format where filenames are on the far right.

   /X     As for /N but with the short filenames included.

   /C     Include thousand separator in file sizes.    

   /-C    don't include thousand separator in file sizes.

   /4     Display four-digit years




(/Q and /4 are supported in Win 2K and above)



The switches above may be preset by adding them to an environment variable called DIRCMD.

For example: SET DIRCMD=/O:N /S



Override any preset DIRCMD switches by prefixing the switch with -

For example:

DIR *.* /-S



Filenames longer than 8 characters

- DIR will always display the filename with the CASE as entered



Filenames shorter than 8 characters

- DIR may display the filename in upper or lower case - this may vary from one client to another (registry setting)



To obtain a bare DIR format (no heading or footer info) but retain all the details, pipe the output of DIR into FIND, this assumes that your date separator is /



DIR c:\temp\*.* | FIND "/"

FOR /f "tokens=*" %%G IN ('dir c:\temp\*.* ^| find "/"') DO echo %%G



Normally DIR /b will return just the filename, however when displaying subfolders with DIR /b /s the command will return a full pathname.



Checking filesize during a download (to monitor progress of a large download)



   TYPE file_being_downloaded >NUL

   DIR file_being_downloaded



Since TYPE won't lock the file_being_downloaded in any way, this doesn't pose a threat to the download itself.






About the Author

FortyPoundHead has posted a total of 1974 articles.


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.163.209.109

Before you can post, you need to prove you are human. If you log in, this test goes away.




Recent Forum Posts

Advanced search added
dwirch posted on September 23, 2017 at about 13:44 in Site News

Job Spammer: Gaurav Mehta - AgreeYa Solutions
dwirch posted on September 22, 2017 at about 10:35 in Spammers

Job Spammer: Prutha Siri - Javelin Systems
dwirch posted on September 10, 2017 at about 6:15 in Spammers

New security implemented
dwirch posted on September 7, 2017 at about 7:16 in Site News

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers