2016-11-23 6 views
-2

以下の場所にあるフォルダを別の場所にコピー&ペーストするプログラムを見つけてください: 実行中になどのエラーは:(この時点では予想外だった(この時点で予期しなかったことです)< - はバフスクリプトの実行中にエラーが発生しました

@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

コマンドラインは、多くの場合など括弧、引用符などの特殊文字、いじりそしてれます。どこにでも設定されていないと、おそらく理由があります.Communixのラインでは、それらが期待されています...

これを読んでも問題が見つからないので、cmd-lineの角括弧を明確にしてください。

だから、それは試して動作しない場合

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

を、私はあなたが2つの括弧、一つの開口部と1を見逃していると思います閉鎖。

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 
    ) 
) 

、彼らはその後、適切なバランスでなければなりませんから、あなたの場合はブロックを変更することで

スタート。

関連する問題