Windows 如何从forfiles变量fname中删除引号

Windows 如何从forfiles变量fname中删除引号,windows,command-line,batch-file,command,dos,Windows,Command Line,Batch File,Command,Dos,有人能告诉我怎么做吗? 问题是@fname包含引号,因此将%source%和@fname合并会产生错误 forfiles /P "%source%" /M %file%.* /D -1 /C "cmd /c if exists %source%\@fname.pdf del @path" 双引号不是问题所在。您的命令行中有一个语法错误:如果存在,它应该转到ifexist。,而不是if-exists…,这是完整的脚本 @echo off set ERRORLEVEL=0 ::variables

有人能告诉我怎么做吗?

问题是
@fname
包含引号,因此将
%source%
@fname
合并会产生错误

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

双引号不是问题所在。您的命令行中有一个语法错误:如果存在,它应该转到
ifexist

,而不是
if-exists…
,这是完整的脚本

@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

:: *********************************************************************************************

问题是它已经在引号之间了,所以上面的方法不起作用。@grmbl你说得有道理。在forfiles命令tail中,可以使用0x22。这将有助于保护%source%不受空格和其他有毒字符的影响<代码>如果存在0x22%source%0x22\@fname.pdf