【问题标题】:Using file-name as parameter in batch file在批处理文件中使用文件名作为参数
【发布时间】:2015-02-04 15:28:33
【问题描述】:

我有这样的事情

FOR %%A IN ("Drawings\*.txt") DO draw.exe /f %%A /d ONLY_FILENAME

但我需要将每个 txt 文件的文件名作为“/d ...”参数自动放入字符串中。

示例: 我的图纸目录中有文件“The First File.txt”。而且自动生成的字符串必须是这样的

FOR %%A IN ("Drawings\*.txt") DO 

draw.exe /f "Drawings\The First File.txt" /d "The First File"

怎么做?

【问题讨论】:

    标签: batch-file filenames rename batch-processing


    【解决方案1】:
    FOR %%A IN ("Drawings\*.txt") DO draw.exe /f "%%A" /d "%%~nA"
    

    ?

    以下是 FOR 帮助的摘录:

    In addition, substitution of FOR variable references has been enhanced
    You can now use the following optional syntax:
    
    %~I         - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    %~pI        - expands %I to a path only
    %~nI        - expands %I to a file name only
    %~xI        - expands %I to a file extension only
    %~sI        - expanded path contains short names only
    %~aI        - expands %I to file attributes of file
    %~tI        - expands %I to date/time of file
    %~zI        - expands %I to size of file
    %~$PATH:I   - searches the directories listed in the PATH
                   environment variable and expands %I to the
                   fully qualified name of the first one found.
                   If the environment variable name is not
                   defined or the file is not found by the
                   search, then this modifier expands to the
                   empty string
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-11
      • 1970-01-01
      • 2014-02-26
      • 1970-01-01
      • 2020-06-05
      • 2019-08-01
      • 2012-07-13
      • 2019-05-25
      相关资源
      最近更新 更多