Windows10 如何使用批处理文件将文件从U 盘复制到C 盘?

How to copy a file from a USB drive to C drive in Windows 10 using a batch file?

我的 U 盘中有一些文件需要复制到多台计算机上。这些文件包含将使用其他配置文件的可执行文件。 我的问题是,对于 Windows 10 台电脑,在创建 temp_folder 的同时,复制了 none 的文件。

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

批处理文件内容如下:

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

我已经尝试使用 xcopy 和 robocopy,但仍然看到批处理文件 运行,只是在创建文件夹时停止。 Windows 7.

中未观察到相同的问题

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

Powershell 是你的朋友,试试这个:

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

对我来说很棒,它甚至可以创建目标目录,Copy-Item 也有 alias cpcopy.

如果您 运行 某种脚本,您可能会遇到 Execution-Policy 问题:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6

这会是一个更好的选择,我们不需要担心 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"