如何使用批处理文件将文件从USB驱动器复制到Windows 10中的C驱动器?

时间:2019-05-09 06:14:50

标签: windows batch-file copy-paste usb-drive

我在USB驱动器中有一些文件需要复制到多台计算机。这些文件包含将使用其他配置文件的可执行文件。 我的问题是,对于Windows 10 PC,在创建temp_folder时,没有文件被复制。

对于Windows 7,我能够创建一个批处理文件,该文件将文件复制到本地驱动器并使用配置文件运行可执行文件。

批处理文件的内容如下:

mkdir C:\temp_installer
copy ".\file_name" "C:\temp_installer"
<rest of the code>

我尝试使用xcopy和robocopy,但仍看到批处理文件正在运行,只是停止创建文件夹。在Windows 7中未观察到相同的问题。

有人尝试过这个吗?或者有人可以告诉我我可能做错了什么吗?

2 个答案:

答案 0 :(得分:1)

这将是一个更好的选择,我们不需要在C:根目录上就权限问题感到困惑

@echo off
cd /d "%~dp0"
set "inst_dir=%temp%\temp_installer"
mkdir "%inst_dir%">nul 2>&1
for %%i in (*) do if not "%%i"=="%~nx0" copy /Y "%%i "%inst_dir%"
:# When completed, we can call execute the files from "%inst_dir%"

说实话,for循环不是必需的,我只是这样做是为了.bat / .cmd文件本身复制到该文件夹​​中,如下所示:

或更简单,而不必执行上述所有操作,您只需使用robocopy

@echo off
cd /d "%~dp0"
robocopy /MIR .\ "%temp%\temp_installer"

答案 1 :(得分:0)

Powershell是您的朋友,请尝试以下方法:

Copy-Item E:\Document\ C:\Temp\Document\ -R

非常适合我,它甚至可以创建目标目录,Copy-Item也具有alias cpcopy

如果运行某种脚本,则Execution-Policy可能有问题:came from