需要一些編碼方面的幫助,我想寫一個bat文件,當它被解僱時,會查找一個USB驅動器,然後複製一個目錄給它。而如果USB沒有插好,就會坐下來,等待用戶將其插入下面的代碼我到目前爲止:問題動態查找USB並備份到它?
@echo off
COLOR 70
@title Finding and Backing Up
@echo Please plug in your USB.
:Find
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
IF EXIST %%a:\backupusb.id SET %%USBDRV=%%a: && GOTO UniTest:
)
GOTO :Find
echo I will look for your work and ensure it's backed up against the USB's Database, please wait.
:UniTest
IF EXIST "%USERPROFILE%\Documents\University" (
echo Found University work, please wait while it's backed up.
xcopy "%USERPROFILE%\Documents\University" "%USBDRV%\Backups\University" /S /D /Y /I /E > nul
echo University work located and successfully backed up.
GOTO End:
) ELSE (
echo I could not find any University folder in your Documents folder
GOTO End:
)
:exit
echo Done!
唯一的問題是,我在編碼方面還是比較晦澀的,當它插入USB插口時,一插入USB,它就會繼續執行腳本,但它會將其轉儲到隨機硬盤上,通常是C :/。我似乎無法弄清楚我出錯的地方,知道我的運氣真是太小了。
任何建議或解決方案?非常感激! 謝謝 -Julian
是否'SET %% USBDRV = %% a:'錯字或鍵入錯誤,或者應該是'SET'USBDRV = %% a:「'? – JosefZ 2015-01-21 11:25:53