|
1 | 1 | @ECHO off
|
| 2 | + |
| 3 | +REM Exit codes for xcopy |
| 4 | +REM code | Description |
| 5 | +REM 0 | Files were copied without error. |
| 6 | +REM 1 | No files were found to copy. |
| 7 | +REM 2 | The user pressed CTRL+C to terminate xcopy. |
| 8 | +REM 4 | Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line. |
| 9 | +REM 5 | Disk write error occurred. |
| 10 | + |
2 | 11 | SET SOURCE=%2
|
3 | 12 | SET SRC_PARSE=%SOURCE:/=\%
|
4 | 13 | SET TARGET=%4
|
| 14 | +SET TARGET=%TARGET:\=% |
| 15 | + |
5 | 16 | setlocal enabledelayedexpansion
|
6 |
| -for /F "skip=1 tokens=*" %%a in ('WMIC LOGICALDISK where "volumename like '%TARGET%%%'" get deviceid') do if not defined id set id=%%a |
7 |
| -Call Set "deviceid=%%id: =%%" |
8 |
| -if not "%deviceid%" == "" (XCOPY %SRC_PARSE% %deviceid% /Y /Q >NUL |
9 |
| -echo Upload complete ) else ( echo %TARGET% not found. Please ensure the device is correctly connected) |
| 17 | +call :parse %TARGET% |
| 18 | +if !errorlevel! == 7 (echo %TARGET% not found. Please ensure the device is correctly connected.) |
| 19 | +exit /b !errorlevel! |
| 20 | + |
| 21 | +:parse |
| 22 | +setlocal enabledelayedexpansion |
| 23 | +set list=%1 |
| 24 | +set list=%list:"=% |
| 25 | + |
| 26 | +for /f "tokens=1* delims=," %%a in ("%list%") DO ( |
| 27 | + if not "%%a" == "" call :sub %%a |
| 28 | + if !errorlevel! LEQ 5 (exit /b !errorlevel!) |
| 29 | + if not "%%b" == "" (call :parse "%%b") |
| 30 | +) |
| 31 | +exit /b !errorlevel! |
| 32 | + |
| 33 | +:sub |
| 34 | +setlocal enabledelayedexpansion |
| 35 | +for /F "skip=1 tokens=*" %%a in ('WMIC LOGICALDISK where "volumename like '%1'" get deviceid 2^>NUL') do if not defined id set id=%%a |
| 36 | + call Set "deviceid=%%id: =%%" |
| 37 | + if not "%deviceid%" == "" ( |
| 38 | + XCOPY %SRC_PARSE% %deviceid% /Y /Q |
| 39 | + if !errorlevel! == 0 (echo Upload complete on %1 ^(%deviceid%^)) |
| 40 | + exit /b !errorlevel!) |
| 41 | +exit /b 7 |
0 commit comments