Page 1 of 1

Copy Specific rar file to specific folder on drive

Posted: 12 Apr 2023 11:55
by foncesa
Hi.
we have multiple rar files in folder d:/data files named as 001.rar, 002.rar, 003.rar, ...
Now i want this rar files to be copied on drive folder Y:/ where i have folders 001/002/003....
Copy specific rar file to specific folder in drive Y
I will highly thankful for help.

Re: Copy Specific rar file to specific folder on drive

Posted: 16 Apr 2023 12:25
by bxx
This should work:

Code: Select all

for %i in (D:\MyRarFiles\*.rar) do (copy %i Y:\%~ni\)
Don't forget: If you're putting this into a batch script, replace each percent sign with two percent signs.

Re: Copy Specific rar file to specific folder on drive

Posted: 19 Apr 2023 13:03
by jaejunks
Use this.

Code: Select all

@echo off
setlocal
set "src=d:\data"
set "dest=y:\"
2>nul cd /d "%src%"
if errorlevel 1 (
  echo Source folder is not found or inaccessible.
  goto :eof
)
2>nul pushd "%dest"%"
if errorlevel 1 (
  echo Destination folder is not found or inaccessible.
  goto :eof
)
popd
set num=1
:loop
set n=00%num%
set n=%n:~-3%
if exist %n%.rar (
  echo %n%.rar =^> %dest%\%n%
  2>nul md "%dest%\%n%"
  >nul copy %n%.rar "%dest%\%n%"
  if errorlevel 1 goto :eof
  set /a num+=1
  goto loop
)