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

时间:2013-08-14 07:43:02

标签: 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"

2 个答案:

答案 0 :(得分:3)

双引号不是问题。您的命令行中出现语法错误:而不是if exists …它应该if exist

答案 1 :(得分:0)

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

@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

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