不知道CMD中USB的目的地 [英] Not knowing the destination of USB in CMD
问题描述
我正在尝试使用批处理文件(.bat)将文件从USB驱动器自动复制到PC中
I am trying to copy files from my USB drive to my PC automatically by using a batch file (.bat)
我知道我可以做类似的事情
I know I can do something like that
xcopy "C:\xxxx\xxxx\xxxx.xxx" "C:\xxxx\xxx\xxxx\xxx.exe" /E /H /I
但是我遇到了一个小问题...
But I faced a little problem...
如果我不知道USB插入驱动器的确切字母怎么办?我如何能够自动复制这些文件?如果可以的话,有人可以从USB向PC发布一个简单的"xcopy"命令.
What if I don't know the exact letter of the drive, where the USB is inserted? How am I able to copy those files automatically? If this is possible, can someone please post a simple "xcopy" command from USB to PC.
谢谢!
推荐答案
能否将通用文件添加到USB驱动器的根目录,以便对其进行测试以发现USB驱动器的驱动器号?例如,如果您在USB驱动器的根目录中创建了一个名为 USBDrive1
的文件,则可以执行以下操作:
Can you add a generic file to the root of the USB drive so you can test for it to discover the drive letter of the USB drive? For instance, if you created a file called USBDrive1
in the root of the USB drive, you could do something like this:
for %%i in (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 %%i:\USBDrive1 set USBDrive=%%i
然后,可以将%USBDrive%
用作其余批处理文件中的驱动器号.像这样:
Then you can use %USBDrive%
for the drive letter in the rest of your batch file. Like this:
xcopy %USBDrive%:\*.* C:\Some\Path ...
这篇关于不知道CMD中USB的目的地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!