简体   繁体   English

如果在XP中“适合范围”,则将文件移动到可变的驱动器位置

[英]Move file to a changeable drive location if fitted “for a in range” in XP

How to move a file to a USB drive that has a variable drive letter range dependant on the machine it could be drive E, F, G or H, in Windows Embedded XP, there is only ever one USB drive installed at a time, so it can move only if it is fitted, I can create the file and it moves in Windows 7 but not in Windows Embedded XP, what are the differences in the options available for this in XP, the script will only be used on XP machines. 在Windows Embedded XP中,如何将文件移动到具有可变驱动器号范围的USB驱动器,具体取决于它可能是驱动器E,F,G或H的机器,因此一次只能安装一个USB驱动器,因此它只有在安装了它之后才能移动,我可以创建文件,并且它可以在Windows 7中移动,但在Windows Embedded XP中不能移动,在XP中可用的选项有什么区别,该脚本仅在XP计算机上使用。

REM ------ Creation of the ZIP file ------

%SupervisorPath%\7-ZipPortable\App\7-Zip\7z a -tzip %BackupPath%\Backup\%FileStamp%.zip %BackupPath%\Backup\

REM ------ Move the backup file to a USB drive with File Name and Date Stamp ------

for %%A in (E F G H) do if exist %%A: (
  echo Moving files to USB drive %%A:
  move /y "%BackupPath%\Backup\%FileStamp%.zip" %%A: >nul && (
    echo Files moved to USB drive successfully
    goto :break
  )
)
:break

Can I also create an error message if the file is not moved and then delete the file, as it takes up valuable space on the drive? 如果文件没有移动然后删除文件,因为它占用了驱动器上的宝贵空间,是否还会创建一条错误消息?

Here is a solution I use. 这是我使用的解决方案。 There is a requirement that the USB drive has been named and you know it. 必须已命名USB驱动器并且您知道它。 So lets say your USB is named "8GB" 因此,假设您的USB名为“ 8GB”

If you run the following command: 如果运行以下命令:

wmic logicaldisk list brief

You get a list of your drives including the VolumeName. 您将获得驱动器列表,包括VolumeName。

Using this list you can pipe it to the Find command like so: 使用此列表,您可以将其通过管道传递给“查找”命令,如下所示:

wmic logicaldisk list brief | find "8GB"

Which will return all information about your drive with the VolumeName 8GB. 它将返回有关VolumeName 8GB的驱动器的所有信息。 It will look something like this. 它看起来像这样。

C:\>wmic LOGICALDISK LIST BRIEF | FIND "8GB"
F:        2          3080192                                     8082407424     8GB

Now with this command we can take it further and redirect its output to a file. 现在,使用此命令,我们可以更进一步,并将其输出重定向到文件。 Like so. 像这样

wmic logicaldisk list brief | find  "8GB" > C:\tmp\usbdriveinfo.txt

After the information we want has been stored we can read it back into a variable using: 存储了我们想要的信息之后,我们可以使用以下命令将其读回到变量中:

set /p driveLetter=C:\tmp\usbdriveinfo.txt

Now that variable has the whole string but we only want the drive letter so we shorten it like so: 现在该变量具有整个字符串,但我们只需要驱动器号,因此我们将其缩短为:

set driveLetter=%driveLetter:~-,2%

Now the variable driveLetter contains just your drive letter "F:" 现在变量driveLetter仅包含驱动器号“ F:”

So if you want it all together: 因此,如果您想要全部在一起:

wmic logicaldisk list brief | find  "8GB" > C:\tmp\usbdriveinfo.txt
set /p driveLetter=C:\tmp\usbdriveinfo.txt
set driveLetter=%driveLetter:~-,2%

As for checking if the move command fails. 至于检查move命令是否失败。 If any command fails move included they set the variable errorlevel to some value other than 0 (0 is for successful execution) Therefore all you need to do is add an if statement after the move command like: 如果任何命令移动失败,则将变量errorlevel设置为0以外的其他值(0表示成功执行)。因此,您要做的就是在move命令后添加if语句,例如:

if %errorlevel% GTR 0 del %BackupPath%\Backup\%FileStamp%.zip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM