我想创建一个批处理文件,将文件从任何目录复制到根文件夹中,.bat文件就像U盘一样位于根文件夹中。
我的命令不完整:
xcopy /s "%userprofile%\Desktop\test.txt" "?"我可以用"?“替换什么?谢谢你们
发布于 2013-11-23 11:54:37
这将完全按照您希望的方式对任何和所有连接的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 (
xcopy /s "%userprofile%\Desktop\test.txt" %%i\
)
)发布于 2013-05-29 19:26:04
xcopy /s "%userprofile%\Desktop\test.txt" "\"发布于 2013-05-29 19:38:28
您应该将其替换为U盘的驱动器号,然后是:\,所以,真正的问题是如何确定系统中的哪些驱动器是U盘,我猜?代码如下:
@echo off
setlocal enabledelayedexpansion
set INTEXTFILE=temp.txt
set OUTTEXTFILE=temp.bat
set SEARCHTEXT='Removable Disk'
set REPLACETEXT=
set OUTPUTLINE=
wmic logicaldisk get name,description|grep -h "Removable" > %INTEXTFILE%
for /f "tokens=3,* delims= " %%A in ( '"type %INTEXTFILE%"') do (
SET string=%%A
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!
)
echo xcopy /s "%userprofile%\Desktop\test.txt" !modified! > %OUTTEXTFILE%
call %OUTTEXTFILE%
del %OUTTEXTFILE%
del %INTEXTFILE%但要考虑到,它肯定只适用于1个可移动磁盘。如果插入两个这种类型的设备,它将失败。
https://stackoverflow.com/questions/16811296
复制相似问题