2012-04-13 42 views
2

我试图创建一个备份批处理文件来自动执行Acronis True Image和备份维护。批处理文件和可变USB驱动器号

取决于USB驱动器盘符更改哪台机器上,我备份和/或多少台设备连接,并使用驱动器号...

我的批处理位于C:\ 我的批次会打电话给ATI。 ATI转储将图像投影到C:\ 然后将批查找我的外部基于其卷序列号,像这样:

SET SN=30BC-F5A4 
SET found= 

0>NUL SET /P=Searching for external drive... 
TIMEOUT 3 /NOBREAK >NUL 

FOR %%N IN (D E F G H I J K L M O P Q R S T U V W X Y Z) DO (
IF defined found CALL :MOVE 
VOL %%N: 2>NUL | FIND "%sn%" >NUL && CALL :MOVE %%N 
) 

ECHO Fail^^! 
TIMEOUT 3 /NOBREAK >NUL 

ECHO. 
ECHO Connect it now and cancel "Autoplay". 
TIMEOUT 3 /NOBREAK >NUL 

ECHO. 
ECHO Press any key to try again... 
PAUSE >NUL 

CALL: EXTERNAL 



:: ***MOVE BACKUP*** 

:MOVE 

OK,那工作不错,但什么我需要现在是沿着线的东西的;

根据序列号查找正确的外部设备。 (如上) 抓住正确的驱动器号并将其变成一个变量。 找到驱动器号并将其变为变量时,跳出FOR IN DO循环。 使用变量来检查文件夹是否存在。 如果该文件夹不存在,请创建它。 如果该文件夹确实存在,请检查是否存在MyBackup.tib。 如果是这样,请删除文件。 CHDIR或某些情况下回到批处理所在的位置(C:\)和MOVE新创建的备份到外部文件夹中。

我在这个问题上直接工作了十个小时,我并没有比我在开始时更接近找到正确的语法/命令。

请问,你能帮忙吗? 我给你一个饼干,哈哈!

我运行Windows 7旗舰版是否有帮助?

+0

的PowerShell或MSYS的选项? – 2012-04-13 19:44:07

+0

不,我想远离安装任何东西。我将在朋友和家庭计算机上使用此批处理,所以... – S3NTYN3L 2012-04-13 19:45:22

回答

6

的序列号为十六进制数字(与抛出很像逗号用作十进制数千位分隔符破折号)。

WMIC volume get driveLetter, serialNumber可用于以十进制表示法获得所有驱动器号的序列号列表。您的30BC-F5A4的序列号等于十进制817690020.我使用命令行上的以下命令将您的十六进制SN转换为十进制形式:set /a 0x30BCF5A4

因此,下面的命令将设置一个变量到您的外部驱动器的驱动器号(带冒号)。

set SN=817690020 
set "extDrive=" 
for /f %%D in ('wmic volume get driveLetter^, serialNumber ^| find "%sn%"') do set extDrive=%%D 
if not defined extDrive echo Error finding external drive & exit /b 

我不明白你说的文件夹名称的来源。我假设你有一个变量与定义的值不知何故。我只是简单地命名变量“文件夹”。

set folder=someFolderName 
if not exist "%extDrive%\%folder%\" mkdir "%extDrive%\%folder%" 

可以使用MOVE命令到新创建的备份移动到文件夹的外部驱动器,自动覆盖任何现有的备份,如果它已经存在。

move /y "c:\MyBackup.tib" "%extDrive%\%folder%\" 
+0

您可以保留原始的'SET SN'命令并在其后添加转换:SET/A SN = 0x%SN: - =%'。 – 2012-04-14 14:44:56

+1

糟糕:'如果未定义'%extDrive%\%文件夹%\“mkdir”%extDrive%\%文件夹%“'。你的意思是“如果不存在......”,对吗? – 2012-04-14 14:49:17

+0

完美,谢谢! – S3NTYN3L 2012-04-14 16:21:44

1

您可以要求盘符,这样的:

说出一些你需要备份的照片是在我们的目录驱动器上的A \ B \ C,其信计算机之间的变化。而且,你要备份你的照片到你的主驱动器,以目录X \ Y \ Z^ 主驱动器(驱动器C :)

set /p Path="Enter the drive letter for your drive on this computer. No symbols, just the capital letter" 
xcopy /e /v %Path%:\a\b\c c:\x\y\z 

你甚至可以要求备份的路径,像这样...

set /p Path="Enter the drive letter for your removable drive on this computer. No symbols, just the capital letter." 
set /p PathBackUp="Enter the path to where you want your data to be backed up on this computer. Start with a backslash." 
set /p BackupDrive="Enter the drive letter for your data to be backed up to on this computer. No symbols, just the capital letter." 
xcopy /e /v %Path%:\a\b\c %BackupDrive%:%PathBackUp% 

或两个...

set /p Path="Enter the drive letter for your removable drive on this computer. No symbols, just the capital letter." 
set /p DataPath="Enter the path where your data to be backed up is. Start with a backslash, and don't include the drive letter. 
set /p PathBackUp="Enter the path to where you want your data to be backed up on this computer. Start with a backslash, and don't include the drive letter." 
set /p BackupDrive="Enter the drive letter for your data to be backed up to on this computer. No symbols, just the capital letter." 
xcopy /e /v %Path%:%DataPath% %BackupDrive%:%PathBackUp% 

我想这种失败的自动化的目的,而仅仅是一个想法;也许这会有所帮助。

有关xcopy命令和修饰符的更多信息,请参阅http://www.computerhope.com/xcopyhlp.htm

有关set命令的详细信息,请参阅http://www.computerhope.com/sethlp.htm

0

这将只需找到连接到系统的所有USB驱动器。

@echo off 

for /F "usebackq tokens=1,2,3,4 " %%i in (`wmic logicaldisk get caption^,description^,drivetype 2^>NUL`) do (

if %%l equ 2 (
echo %%i is a USB drive. 
     ) 
     ) 
0

我到处寻找,并试图很多东西 - 这是最快的,最简单的驱动器盘符交换机命令行选项

echo off 

set /p Path="Enter the Drive Letter of the source File then press enter___" 

set /p Pathde="Enter the Drive Letter of the Destination File then press enter___" 

echo on 

COPY %path%:\Users\Dell\Desktop\test.txt %pathde%:\test.txt 
相关问题