I need help with writing a batch script for
if file newfile.txt exists
then del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
Thanks in advance,
Joe
I need help with writing a batch script for
if file newfile.txt exists
then del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
Thanks in advance,
Joe
if not exist newfile.txt goto skip
del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
:skip
You can use simple curved brackets (also supporting else!)
@echo off
IF EXIST newfile.txt (
del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
)
With else:
@echo off
IF EXIST newfile.txt (
del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
) else (
echo Making tea
)
Hi Joe,
One way you can do this is to is to have if statements and labels for both error and success and use ECHO to debug it... my example here has to do with directories, but surely you can adapt for you file deletion/creation needs:
ECHO Cleaning up folders...
if exist %myDir% goto deleteFolder
goto createNewDir
:deleteFolder
echo Deleting %myDir%
RMDIR %myDir% /S /Q
IF ERRORLEVEL 1 GOTO Error
:createNewDir
mkdir %myDir%
IF ERRORLEVEL 1 GOTO Error
goto Done
:error
echo something went wrong
goto End
:Done
echo Success!
:End
HTH, EB