You can easily add an ECHO command to see what values your variables have. That way you will know for sure whether they are set properly or not.
Anyway, there does seem to be a couple of issues in the posted script.
The first one is this line:
SET PathString = C:\Users\bibhukdas\Documents\New_folder1~C:\Users\bibhukdas\Documents\New_folder
The spaces aroung the =
are important. The one before the assignment becomes part of the variable name and the other one part of the value. So, the above line essentially creates a variable called PathStringÂ
, i.e. with a trailing space character. To fix this issue, just remove both spaces.
One other is the for
loop line. The delims
option is followed by a space, which is invalid and will cause a syntax error. Again, just remove the space.
There's also an issue of a different kind. You are not omitting the source unavailable
output after the robocopy
command, which means you would get the source unavailable
line in your log despite the the files having been copied. That should be easily fixed by adding a GOTO :EXIT
command just after the robocopy
line. However, you could also do like this:
if "%Source1%" == "0" (
echo *****source unavailable******* >>C:\Users\bibhukdas\Documents\New_folder\log.txt
) else (
robocopy.exe %Source1% %Destination1% *.doc /COPY:DAT /MINAGE:5 /R:1 >> C:\Users\bibhukdas\Documents\New_folder\log.txt
)
Finally, you could improve maintainability of your script by reducing the number of output redirections.
A redirection can be applied to a bracketed block of commands, like this:
(
command1
command2
command3
...
) >outputfile
So, you could apply the redirection to C:\Users\bibhukdas\Documents\New_folder\log.txt
to all your commands that require it this way:
(
echo ******start****
echo ******POINT1****
echo "%PathString%"
for /f "tokens=1,2 delims=~" %%a in("%PathString%") do set Source1=%%a&set Destination1=%%b
echo ******POINT1****
if "%Source1%" == "0" (
echo *****source unavailable*******
) else (
robocopy.exe %Source1% %Destination1% *.doc /COPY:DAT /MINAGE:5 /R:1
)
) >>C:\Users\bibhukdas\Documents\New_folder\log.txt
Note, however, that the for
loop will have to moved outside the block. This is because it sets variables that are later evaluated (using the %
expansion) in the same block, which doesn't work as expected. This is one of the effects of a bracketed block. You could use delayed expansion here, but in this particular case it is much easier to just move the assignment outside the block.
So, after addressing all of the issues mentioned, your script might look like this:
@echo off
SET PathString=C:\Users\bibhukdas\Documents\New_folder1~C:\Users\bibhukdas\Documents\New_folder
for /f "tokens=1,2 delims=~" %%a in("%PathString%") do set Source1=%%a&set Destination1=%%b
(
echo ******start****
echo ******POINT1****
echo "%PathString%"
echo ******POINT1****
if "%Source1%" == "0" (
echo *****source unavailable*******
) else (
robocopy.exe %Source1% %Destination1% *.doc /COPY:DAT /MINAGE:5 /R:1
)
) >>C:\Users\bibhukdas\Documents\New_folder\log.txt