I have a relatively simple batch file with some if-else blocks and any variable that I define within the else do not get set. If I break the else and have the same code outside of the else block it works.
With Echo ON, the set command shows what it should be doing but it does not execute it. Any comments please.
IF NOT EXIST "%DeployPath%" (
echo "PingFed Deploy Path is not found ... please locate: %DeployPath%"
dir "%DeployPath%"
goto :End1
) ELSE (
echo Source Directory: %DeployPath%
echo ------------------------------
set ArchPath=%DeployPath%\%ArchFolder%_%dateTime%
echo "path: %ArchPath%"
mkdir "%ArchPath%"
mkdir %DeployPath%\%ArchFolder%_%dateTime%
)
=========
The same ELSE code outside of the ELSE Block works
echo Source Directory: %DeployPath%
echo ------------------------------
set ArchPath=%DeployPath%\%ArchFolder%_%dateTime%
echo "path: %ArchPath%"
mkdir "%ArchPath%"
mkdir %DeployPath%\%ArchFolder%_%dateTime%```
Running the script with the ELSE Block with Echo ON:-
```C:\utils>IF NOT EXIST "C:\Blah\Runtime1\deploy_orig" (
echo "PingFed Deploy Path is not found ... please locate: C:\Blah\Runtime1\deploy_orig"
dir "C:\Blah\Runtime1\deploy_orig"
goto :End1
) ELSE (
echo Source Directory: C:\Blah\Runtime1\deploy_orig
echo ------------------------------
set "ArchPath=C:\Blah\Runtime1\deploy_orig\Archive_20190418_104501"
echo "path: "
mkdir ""
mkdir C:\Blah\Runtime1\deploy_orig\Archive_20190418_104501
)
Source Directory: C:\Blah\Runtime1\utils\default\deploy_orig
------------------------------
"path: "
The filename, directory name, or volume label syntax is incorrect.```
Running the script without the Else Block with Echo ON gives the correct results:-
Source Directory: C:\Blah\Runtime1\deploy_orig
C:\utils>echo ------------------------------
------------------------------
C:\utils>set ArchPath=C:\Blah\Runtime1\deploy_orig\Archive_20190418_105932
C:\utils>echo "path: C:\Blah\Runtime1\deploy_orig\Archive_20190418_105932"
"path: C:\Blah\Runtime1\deploy_orig\Archive_20190418_105932"
C:\utils>mkdir "C:\Blah\Runtime1\deploy_orig\Archive_20190418_105932"
C:\utils>mkdir C:\Blah\Runtime1\deploy_orig\Archive_20190418_105932
A subdirectory or file C:\Blah\Runtime1\deploy_orig\Archive_20190418_105932 already exists.
Aucun commentaire:
Enregistrer un commentaire