批量脚本备份USB中的文件 [英] Batch Scripting Backing up files in USB

查看:44
本文介绍了批量脚本备份USB中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IV使我的代码显示了连接到笔记本电脑的USB设备的列表,我也可以选择USB,但是当我尝试将文件夹备份到USB时,我得到的是文件夹中名为f的文件夹我试图保存.这是我用于选择USB设备的代码

Iv got my code to show a list of USb devices connected to my laptop and i can select the USB as well but when i try to back up a folder into the USB what i get instead is a folder named f in the folder i was trying to save. This is the code i have for selectong a USB device

for /f "delims=" %%a in ('wmic logicaldisk where drivetype^=2 get deviceid ^| find ":"') do set "$List=!$List! %%a"

:USB  
echo Avaiable Drive ==^> !$List!
set /p "$Drive=Enter the letter of the Backup drive : "

echo !$List! | find /i "%$Drive::=%:" && Echo drive OK || Echo drive do not exist && goto:USB

set backupcmd=robocopy

这是备份文件夹的代码

%backupcmd% "%cd%" "%$Drive%"

推荐答案

一次尝试一下:

@echo off
setlocal enabledelayedexpansion
set num=0
for /f  %%a in ('wmic logicaldisk where drivetype^=2 get drivetype^, deviceid ^| find ":"') do (
    set /a num+=1
    set cnt=!cnt!!num!
    echo (!num!^) %%a
    set "d!num!=%%a"
)
choice /c !cnt! /M "select a number to choose a drive: "
echo You've chosen drive !d%errorlevel%! you can do everything with it from here..

您会注意到,由于在括号代码块内设置和使用了变量,我在这里设置了 delayedexpansion .

You will notice that I set delayedexpansion here because of the setting and using of variables inside of the parenthesised code block.

在这里选择"Choice"是个不错的选择,因为它不允许键入错误的值.

Choice is a good option here as it does not allow typing the wrong values.

这篇关于批量脚本备份USB中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆