2016-11-23 5 views
-2

Ниже приведена программа для копирования папки из одного места в другое. При попытке выполнить ее я получаю ошибка как: (было неожиданным в это время(было неожиданным в настоящее время. <- это ошибка, которую я получаю при запуске скрипта bathc

@echo off 

set /p SrcPath= Source file is 
echo %SrcPath% 

set /p DestPath= Destination file is 
echo %DestPath% 

echo Checking if the package with the same name exists in the Destination Path 

if exist %DestPath% ( 
         echo Folder exists 
         echo Do you want to rename the existing folder Y/N 
         set /p Answer= 
         echo %Answer% 
         if %Answer% == y (echo please suggest what suffix you would like to append e.g. _old, _bkp etc 
              set /p Suffix= 
              move %DestPath% %DestPath%%Suffix% 
              goto :CopyPackage) 


         if %Answer% == n echo "please decide what to do" 
        ) else (echo "folder doesn't exist" 
           goto :CopyPackage) 





:CopyPackage 
ROBOCOPY /s /e %SrcPath% %DestPath% 



Output on cmd prompt: 
C:\Users\shreyash>Z:\Dev\FolderEx.bat 
Source file is C:\New 
C:\New 
Destination file is C:\New1 
C:\New1 
Checking if the package with the same name exists in the Destination Path 
(was unexpected at this time. 
C:\Users\shreyash>Z:\Dev\FolderEx.bat 
Source file is C:\New 
C:\New 
Destination file is C:\New1 
C:\New1 
Checking if the package with the same name exists in the Destination Path 
(was unexpected at this time. 
C:\Users\shreyash>Z:\Dev\FolderEx.bat 
Source file is "C:\New" 
"C:\New" 
Destination file is "C:\New1" 
"C:\New1" 
Checking if the package with the same name exists in the Destination Path 
(was unexpected at this time. 

Просьба предложить какие изменения требуются !!!

+2

Еще раз: [замедленное расширение] (http://ss64.com/nt/delayedexpansion.html) ... – aschipfl

+0

Это не кажется основной проблемой ... При чтении вывода кажется, что самое верхнее утверждение вызывает крушение уже или я ошибаюсь? – geisterfurz007

ответ

0

командной строки часто возни со специальными символами, например, скобки, кавычки и т.д., и это. может быть, причина, если она не установлена ​​повсюду, где линия cmd ожидает их ...

Я не могу найти проблему при чтении этого, поэтому попробуйте уточнить скобки для cmd-линии.

Так что попробуйте

if %Answer% == n (echo "please decide what to do") 

, если он не работает, попробуйте:

if %Answer% == y ( 
echo please suggest what suffix you would like to append e.g. _old, _bkp etc 
set /p Suffix= 
move %DestPath% %DestPath%%Suffix% 
goto :CopyPackage) 
else (echo "please decide what to do") 
) else ( 
echo "folder doesn't exist" goto :CopyPackage 
) 
0

Несмотря на соответствующее число скобок, я думаю, что вы пропустили два круглых скобок, одно отверстие и один закрытие.

Start, изменив, если блок из:

if exist %DestPath% ( 
         echo Folder exists 
         echo Do you want to rename the existing folder Y/N 
         set /p Answer= 
         echo %Answer% 
         if %Answer% == y (echo please suggest what suffix you would like to append e.g. _old, _bkp etc 
              set /p Suffix= 
              move %DestPath% %DestPath%%Suffix% 
              goto :CopyPackage) 


         if %Answer% == n echo "please decide what to do" 
        ) else (echo "folder doesn't exist" 
           goto :CopyPackage) 

к:

if exist "%DestPath%\" ( 
    echo Folder exists 
    echo Do you want to rename the existing folder Y/N 
    set /p Answer= 
    echo %Answer% 
    if %Answer%==y (
     echo please suggest what suffix you would like to append e.g. _old, _bkp etc 
     set /p Suffix= 
     move "%DestPath%" "%DestPath%%Suffix%" 
     goto :CopyPackage 
    ) 
    if %Answer%==n (
     echo "please decide what to do" 
    ) else (
     echo "folder doesn't exist" 
     goto :CopyPackage 
    ) 
) 

, и они должны быть затем правильно сбалансирован.