按标签引用卷/驱动器 [英] Reference a Volume/Drive by Label

查看:28
本文介绍了按标签引用卷/驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个批处理文件来将文件夹复制到可移动 USB 驱动器.但是,我面临的问题是驱动器号可能会更改,因此我希望能够通过引用卷标而不是驱动器号来做到这一点.

I'm trying to write a batch file to xcopy a folder to a removable USB drive. The problem that I face, however, is that drive letters are subject to change, so I would like to be able to do this by referencing the volume label instead of the drive letter.

有什么想法吗?一个小时的谷歌搜索被证明是徒劳的.:(

Any ideas? An hour of Google-ing has proved fruitless. :(

推荐答案

这个命令应该发现带有正确标签的驱动器并将驱动器号(带冒号)存储在变量usb"中

This command should discover the drive with the correct label and store the drive letter (with colon) in variable "usb"

for /f %%D in ('wmic volume get DriveLetter^, Label ^| find "yourLabel"') do set usb=%%D

如果您愿意,可以将 xcopy 命令直接嵌入 DO 子句中.%%D 包含驱动器号.

You could embed your xcopy command(s) directly in the DO clause if you like. %%D contains the drive letter.

这篇关于按标签引用卷/驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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