简体   繁体   中英

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

I have some files in a USB drive which need to be copied to multiple computers. These files contain an executable which will use the other config files. My issue is, for Windows 10 PCs, while the temp_folder gets created, none of the files get copied.

For windows 7 I was able to create a batch file which copied the files to the local drive and ran the executable using the config files.

The batch file contents were as below :

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

I have tried using xcopy and robocopy, but still see the batch file run and just stop at creating the folder. The same issue isn't observed in Windows 7.

Has someone tried this or can someone tell me what I might be doing wrong?

This would be a better option, we do not need to be concerened about permission issues on the root of 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%"

The for loop is not needed to be honest, I am only doing it to not copy the .bat / .cmd file itself to the folder as there would be no need for it there.

Or even simpler, without having to do all the above, you could just use robocopy

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

Powershell is your friend here, try this:

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

Works great for me and it even creates destination directory, also Copy-Item has alias cp and copy .

If you running some sort of script, you might have issues with Execution-Policy : https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM