简体   繁体   中英

How to move multiple files to New Directory

Good Morning All!

I have been working on a verification and move script for our backups at my office. Everything works great except it seems to only be moving the first file in the.txt file it is reading from. I need it to move all the files that are listed in the smc_raw.txt location to the one specified in the script.

Thanks!

@echo off
SET /P dir=Input Start File:
echo.
"C:\Program Files\StorageCraft\spx\image.exe" qp %dir% %1 f=fsr “d=$n” > Z:\StorageCraft\SMC\smc_raw.txt
setlocal
SET LOGFILE=Z:\StorageCraft\SMC\smc_log.txt
SET /P AREYOUSURE=Raw Data has been saved! Check the smc_raw.txt File! Do you want to continue the SMC Copy(Y/[N])?
IF /I "%AREYOUSURE%" NEQ "Y" GOTO END
REM Use /f to read the contents of a file, and %%i to reference the line you just read:
for /f %%i in (Z:\StorageCraft\SMC\smc_raw.txt) do (
    move %%i Z:\StorageCraft\SMC >nul 2>&1
    if errorlevel 1 (
        echo %%i : Move failed >> %LOGFILE%%
    ) else (
        echo %%i : Move successful >> %LOGFILE%
    )
)
break > Z:\StorageCraft\SMC\smc_raw.txt
setlocal

EXAMPLE smc_raw.txt

"Z:\StorageCraft\W10SOLID21VM\C_VOL-b001.spf" "Z:\StorageCraft\W10SOLID21VM\C_VOL-b001-i064-cd-cm-cr.spi" "Z:\StorageCraft\W10SOLID21VM\C_VOL-b001-i094-cd-cm.spi" "Z:\StorageCraft\W10SOLID21VM\C_VOL-b001-i099-cd-cm.spi" "Z:\StorageCraft\W10SOLID21VM\C_VOL-b001-i102-cd-cw.spi" "Z:\StorageCraft\W10SOLID21VM\C_VOL-b001-i109-cd-cw.spi" "Z:\StorageCraft\W10SOLID21VM\C_VOL-b001-i116-cd-cw.spi"

Seeing as you do not have the items in list format, we simply force it to be list format by adding another for to grab the content of the file and store as a variable:

@echo off
SET /P dir=Input Start File:
echo(
"C:\Program Files\StorageCraft\spx\image.exe" qp %dir% %1 f=fsr “d=$n” > Z:\StorageCraft\SMC\smc_raw.txt
SET LOGFILE=Z:\StorageCraft\SMC\smc_log.txt
SET /P AREYOUSURE=Raw Data has been saved! Check the smc_raw.txt File! Do you want to continue the SMC Copy(Y/[N])?
IF /I "%AREYOUSURE%" NEQ "Y" GOTO END
REM Use /f to read the contents of a file, and %%i to reference the line you just read:
for /f "delims=" %%a in (Z:\StorageCraft\SMC\smc_raw.txt) do set "list=%%a"
for %%i in (%list%) do (
    move %%i Z:\StorageCraft\SMC >nul 2>&1
    if errorlevel 1 (
        echo %%i : Move failed >> %LOGFILE%%
    ) else (
        echo %%i : Move successful >> %LOGFILE%
    )
)
break > Z:\StorageCraft\SMC\smc_raw.txt

I am not able to test this as I am not on my laptop, so you have to test it for us.

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