【WINDOWS / DOS 批处理】dir命令参数详解(一)

命令格式

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]参数】

drive 指定 filename 所在的驱动器名称,例如:C、D 

path 指定 filename 的路径

filename 指定文件名(或目录名)

如果 [drive:][path][filename]指定了一个文件,则只显示该文件的信息,如果 [drive:][path][filename]指定了一个目录,则显示该目录中的文件和(或)目录。

同一条dir命令中,可以出现多个 [drive:][path][filename]参数,它们会依次被执行

        示例

C:\>dir /a /b
file_hide.txt
file_show.txt
file_show2.txt
hideDir
showDir

C:\>dir  file_show.txt file_show2.txt /b
file_show.txt
file_show2.txt

C:\>

[ /B参数 ] 

只显示 filename 的名称

[ /A:attributes参数 ] 

attributes 指定要显示的文件(目录)的属性。可选值:D(目录)、R(只读文件)、H (隐藏文件)、A (准备存档的文件)、s ( 系统文件)。如果要表示相反属性, 就使用"-" 作为前缀。例如, -H表示非隐藏属性。

1、“/A:attributes”中,当“:attributes”不存在时,表示全部文件和目录

        示例

C:\>dir /b /a:d          // 显示当前目录下的目录
hideDir
showDir

C:\>dir /b /a:-d         // 显示当前目录下的文件
file_hide.txt
file_show.txt

C:\>dir /b /a:           // 显示当前目录下的文件和目录
file_hide.txt
file_show.txt
hideDir
showDir

C:\>dir /b /a            // 显示当前目录下的文件和目录
file_hide.txt
file_show.txt
hideDir
showDir

C:\>

1、/A参数不存在时,缺省值为 /A: -H

        示例

C:\>attrib file_hide.txt
A   H        C:\out\file_hide.txt

C:\>dir /b file_hide.txt     //  /A参数的缺省值是 -H
找不到文件

C:\>

 2、同一条dir命令中,可以出现多个/A参数,最后一个/A参数会覆盖前面的/A参数

        示例

C:\>dir /a /b                // 显示当前目录下的文件和目录
file_hide.txt
file_show.txt
hideDir
showDir

C:\>attrib ./showDir         // 显示 showDir 目录的属性
             C:\out\showDir

C:\>attrib ./hideDir         // 显示 hideDir 目录的属性
    H        C:\out\hideDir

C:\out>attrib                // 显示当前目录下各个文件的属性
A   H        C:\out\file_hide.txt
A            C:\out\file_show.txt
C:\>dir /b /a:h /a:-d       //  /A参数最终的值为-d
file_hide.txt
file_show.txt

C:\>

 3、/A的值可以是属性组合,可以是:

  • 多个属性的组合,多个属性都生效
  • 单个属性的组合,后面的属性会覆盖前面的属性

         示例

C:\>dir /a /b                // 显示当前目录下的文件和目录
file_hide.txt
file_show.txt
hideDir
showDir

C:\>attrib ./showDir         // 显示 showDir 目录的属性
             C:\out\showDir

C:\>attrib ./hideDir         // 显示 hideDir 目录的属性
    H        C:\out\hideDir

C:\>attrib                // 显示当前目录下各个文件的属性
A   H        C:\out\file_hide.txt
A            C:\out\file_show.txt
C:\>dir /b /a:-dh         // -d属性和 h属性都生效
file_hide.txt

C:\>dir /b /a:-dd        // d属性覆盖了 -d属性
hideDir
showDir

C:\>

写作不易,本文如能帮到您,麻烦您 “在下面一圈三连”。

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值