【问题标题】:What does the "/" mean in this line from a Batch file?批处理文件中这一行中的“/”是什么意思?
【发布时间】:2016-11-03 15:52:25
【问题描述】:

我在这里的一篇文章中找到了这行代码。我将它用于我的批处理文件,它可以工作。我只是想了解 FIND 命令后双引号中的“/”是什么意思。

    dir /a-d "\\SERVERNAME\SHARE\FOLDER\*.ext" | find /C "/"

提前致谢!

【问题讨论】:

  • 这是它需要找到的。

标签: windows batch-file find


【解决方案1】:

它告诉find 命令在重定向到finddir 命令中找到什么字符串。 /c 告诉 find 输出找到目标字符串的行数,因此如果您的日期分隔符是 /,则输出找到的文件数。

【讨论】:

  • 谢谢。我很确定它是为了找到日期分隔符。让我失望的是,如果我把另一个变量放在那里,比如一个“A”,我得到的计数比我用“/”得到的高一个。 (这些文件的名称很长,其中代表了大多数字母。)
【解决方案2】:

如果你输入

FIND /?

在 CMD 窗口中,FIND 会这样告诉你它的用法:

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

  /V         Displays all lines NOT containing the specified string.
  /C         Displays only the count of lines containing the string.
  /N         Displays line numbers with the displayed lines.
  /I         Ignores the case of characters when searching for the string.
  /OFF[LINE] Do not skip files with offline attribute set.
  "string"   Specifies the text string to find.
  [drive:][path]filename
             Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.

所以双引号中的字符串就是您希望FIND 找到的内容。

/? 选项受支持且对许多内置 DOS 命令很有用。

【讨论】:

    【解决方案3】:

    命令行可能用于获取匹配文件的计数。由于dir 返回一个标题、一个包含日期/时间和大小的文件列表以及一个页脚,/ 可能已被选为搜索字符,因为这可能只出现在文件列表的日期中,而不是在额外的行(页眉/页脚)。这是dir /A-D "\\SERVERNAME\SHARE\FOLDER\*.ext" 的示例输出:

     Volume in drive \\SERVERNAME\SHARE is DATA
     Volume Serial Number is 0000-0000
    
     Directory of \\SERVERNAME\SHARE\FOLDER
    
    03/11/2016  12:00                 10 file.ext
    03/11/2016  11:00                 26 sample.ext
                   2 File(s)             36 bytes
                   0 Dir(s)  99,999,999,964 bytes free
    

    如您所见,斜杠字符 (/) 仅出现在日期中,以防它被定义为当前机器上的日期分隔符,这使得整个方法依赖于区域设置。

    管道| 将此输出传输到下一个命令,即find /C "/",该命令会计算至少包含一个/ 字符的行数(/C)。


    如果我的怀疑是正确的,您可以改用以下行:

    dir /B /A-D "\\SERVERNAME\SHARE\FOLDER\*.ext" | find /C /V ""
    

    /B 开关告诉dir 返回一个没有任何额外内容的裸文件列表,例如:

    sample.ext
    file.ext
    

    然后find /C /V "" 命令计数 (/C) 所有不匹配 (/V) 空字符串 ("") 的行,因此它返回给定位置中 *.ext 文件的总数.与原始方法相反,这种方法完全独立于语言环境和区域设置。

    【讨论】:

      猜你喜欢
      • 2013-09-23
      • 1970-01-01
      • 2010-09-11
      • 2023-03-24
      • 2013-05-14
      • 1970-01-01
      • 2012-01-19
      • 2013-03-11
      相关资源
      最近更新 更多