Copy Specific rar file to specific folder on drive

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
foncesa
Posts: 42
Joined: 12 Sep 2013 00:09

Copy Specific rar file to specific folder on drive

#1 Post by foncesa » 12 Apr 2023 11:55

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.

bxx
Posts: 5
Joined: 09 Mar 2023 03:49

Re: Copy Specific rar file to specific folder on drive

#2 Post by bxx » 16 Apr 2023 12:25

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.

jaejunks
Posts: 1
Joined: 19 Apr 2023 12:36

Re: Copy Specific rar file to specific folder on drive

#3 Post by jaejunks » 19 Apr 2023 13:03

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
)

Post Reply