【问题标题】:How can I remove quotes from forfiles variable fname如何从 forfiles 变量 fname 中删除引号
【发布时间】:2013-08-16 01:26:15
【问题描述】:

谁能解释一下如何做到这一点?

问题是 @fname 包含引号,因此连接 %source% 和 @fname 会出错...

forfiles /P "%source%" /M %file%.* /D -1 /C "cmd /c if exists %source%\@fname.pdf del @path"

【问题讨论】:

    标签: windows command-line batch-file command dos


    【解决方案1】:

    双引号不是问题。您的命令行中有语法错误:而不是 if exists … 它应该是 if <strong>exist</strong> …。

    【讨论】:

    • 问题是它已经在引号之间,因此上面的行不通。
    • @grmbl 你说得有道理。在 forfiles 命令中可以使用 0x22。这将保护 %source% 免受空格和其他有毒字符的影响。 if exist 0x22%source%0x22\@fname.pdf
    【解决方案2】:

    对于任何感兴趣的人,这是完整的脚本。

    @echo off
    set ERRORLEVEL=0
    
    ::variables
    set source=C:\ASWFORM\argus
    set ps2pdf=C:\Progra~1\gs\gs9.07\gs\lib\ps2pdf
    
    ::parameters
    
    if [%1]==[] goto hell
    if [%2]==[] goto hell
    
    set file=%1
    set hotfolder=%2
    
    :: *********************************************************************************************
    
    ::delete files from yesterday
    forfiles /P "%source%" /M %file%.* /D -1 /C "cmd /c if exist %source%\@fname.pdf del @path"
    
    ::create pdf files
    forfiles /P "%source%" /M %file%.ps /C "cmd /c call %ps2pdf% @path"
    
    ::move files to hotfolder
    xcopy /Y /V %source%\%file%.pdf %hotfolder%
    xcopy /Y /V %source%\%file%.xml %hotfolder%
    xcopy /Y /V %source%\%file%.adj %hotfolder%
    
    forfiles /P "%source%" /M %file%.* /C "cmd /c if exist %source%\@fname.pdf del @fname.ps"
    
    goto heaven
    
    :hell
    echo Usage argus.bat [filename without extension] [path to archive hotfolder]
    
    :heaven
    exit 0
    
    :: *********************************************************************************************
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-03
      • 2015-12-06
      • 2010-12-29
      • 1970-01-01
      • 1970-01-01
      • 2013-03-18
      • 2021-11-02
      相关资源
      最近更新 更多