简体   繁体   中英

Need Help Writing A Batch Script To Move Certain Files From One Folder To Another

I need help writing a batch script I can run that will take a list of file names ["FileA.jpg", "FileB.jpg", "FileC.jpg"](These file names can be either in a text format or a csv) and finds those files in Folder A and then copies them into Folder B.

If there is an easy way to do this with another kind of script I am definitely open to that. I just need to figure out an automated way to get the job done.

This is the first time I have asked a question and received downvotes... an explanation for that might help as well.

Thank you in advanced for your help.

Try this, it requires a text file which consists of a list of all the files in a simple list format with no quotes called input.txt :

@echo off
setlocal enabledelayedexpansion
set "FolderA=C:\..[path]"
set "FolderB=C:\...[path]"
REM Above do not end the path with "\"

for /f "tokens=*" %%a in (input.txt) do (
copy "!FolderA!\%%~a" "!FolderB!\"
Echo Copied "%%~a" to "!FolderB!"
)

And that should work fine.

Mona

This worked for me

  1. create a txt called list.txt with the list of file names you want to move and save it in your origin folder. 2.use the below code to make a bat file and save it in the origin folder. 3.now run the bat file you saved with admin rights.
  2. the files will be copied in C:\\copied

    @echo off REM (c) 2015 CLS TITLE file finder REM finds files in list.txt file and copies them to C:\\copied REM CHECK FOR ADMIN RIGHTS COPY /b/y NUL %WINDIR%\\06CF2EB6-94E6-4a60-91D8-AB945AE8CF38 >NUL 2>&1 IF ERRORLEVEL 1 GOTO:NONADMIN DEL %WINDIR%\\06CF2EB6-94E6-4a60-91D8-AB945AE8CF38 >NUL 2>&1 :ADMIN REM GOT ADMIN RIGHTS COLOR 1F ECHO Hi, %USERNAME%! ECHO Please wait... FOR /R "%~dp0" %%I IN (.) DO for /f "usebackq delims=" %%a in ("%~dp0list.txt") do echo d |xcopy "%%I\\%%a" "C:\\copies" /e /i COLOR 2F ECHO. ECHO (c) Copying done PAUSE GOTO:EOF :NONADMIN REM NO ADMIN RIGHTS COLOR 4F ECHO. ECHO PLEASE RUN AS ADMINISTRATOR ECHO. pause GOTO:EOF

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