The dir command for resolving dos in Windows Windows uses

Source: Internet
Author: User

Summarize the use of the dir command in cmd

On a 64-bit WIN10 system, print the Help document.

D:\test>dir/?Displays a list of files and subdirectories in the directory. DIR [Drive:][path][filename] [/a[[:]attributes]] [/b] [/C] [/d] [/l] [/N] [/o[[:]sortorder] [/p] [/q] [/R] [/S] [/t[[:]timefield]] [/w] [/x] [/4] [Drive:][path][filename] Specifies the drives, directories, and/or file. /A displays the file with the specified attributes. Property D Directory R read-only file H hidden file a file ready to archive S system file I No content index file L parse Point-Prefix for "no"/B uses an empty format (no header information or summary). /C Displays the thousands separator in the file size. This is the default value. With/-C to disable the display of separators. /d is the same as the wide, but the files are listed by column. /l in lowercase. /n a new long list format with the file name on the far right. /o lists the files in sorted order. Sort order N by name (alphabetical order) S by size (from small to large) E by extension (alphabetical) D by date/ time (binate to post) G-group directory precedence-p pauses after each information screen. /q Displays the file owner. /r displays the alternate data stream for the file. /s displays the files in the specified directory and all subdirectories. /t controls the time character field that is displayed or used for categorization. Time period C creation time A last access time W last write time/w in wide list format. The/x is displayed as a non-8.3 the short name produced by the file name. The format is/n format, the short name is inserted in front of the long name. If there is no short name, the space is displayed in its place. /4 Use a four-digit year to pre-set the switch in the DIRCMD environment variable. By adding a prefix-(dash)               


1. Displays the absolute path of all files under the current path, including the contents of subfolders

d:\test>dir/b/s/o:n/a:ad:\test\a.txtd:\test\b.txtd:\test\c.txtd:\test\a\a.txtd:\test\ B\b.txtd:\test\c\c.txt


/b indicates removal of summary information and shelf displays full path
/s means enumerating the contents of nested folders
/o:n means sorting by file name
/A:A indicates that the file is enumerated only and does not enumerate other

Note: Individual dir/b and dir/s do not show the full path, only these two combinations will show the full path.

2. Displays the absolute path of the directory for all files under the current path


3. Display all the specified file names under the current directory

Of course, you can also find fuzzy queries, such as *.txt

D:\test>dir/p/s A.txtThe volume in drive D is not labeled. The serial number of the volume is0006-7E93 Directory of D:\test2016/10/1416:593 a.txt  1 files 32016/ 10/14 16:59 3 a.txt  1 files 3 2 files 6< Span style= "color: #000000;" > byte  0 directories 94,208,172,032 Available Bytes          

All the content under the nested folder is queried.

4. Traverse all filenames under the current folder

@echo Offrem Enable delay variable setlocal enabledelayedexpansion  set/a v=1for/f "delims=/"%%i in (' dir/b/a-d/on * * ') do (    s et/a v+=1    @echo!v! file name:%%i) Pause

This is used/as a delimiter because the file name cannot be used/signed. The partition is bound to get a full name. If you just want to get the file name and remove the suffix, you can make the following changes:

@echo Offrem enable the delay variable setlocal enabledelayedexpansion  set/a v=1for/f "delims=."%%i in (' dir/b/a-d/on * * ') do (    s et/a v+=1    @echo!v! file name:%%i) Pause

Use "." Here. As a separator, just to show the name of the file, but if there are several "." in a file name. Symbol, then the above method does not apply.

Original link: The dir command for Windows

The dir command for resolving dos in Windows Windows uses

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.