3

Can anyone explain me how to do this?

Problem is @fname contains quotes so concatting %source% and @fname gives an error...

forfiles /P "%source%" /M %file%.* /D -1 /C "cmd /c if exists %source%\@fname.pdf del @path"
grmbl
  • 2,514
  • 4
  • 29
  • 54

2 Answers2

3

The double quotes are not the issue. You've got a syntax error in your command line: instead of if exists … it should go if exist.

Andriy M
  • 76,112
  • 17
  • 94
  • 154
  • problem is that it's already between quotes, thus the above will not work. – grmbl Aug 14 '13 at 08:33
  • 1
    @grmbl You have a point. Within the forfiles command tail you can use 0x22. This will work to protect the %source% from spaces and other poison characters. `if exist 0x22%source%0x22\@fname.pdf` – foxidrive Aug 14 '13 at 09:31
0

For anyone interested this is the full script.

@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
  • 2,514
  • 4
  • 29
  • 54