Archive Folders Winrar

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Archive Folders Winrar

#1 Post by foncesa » 20 Jan 2014 12:20

Hello,

I want to Archive the folders with WinRAR the folder layout is like this.

C:\Data\Company\<folder1>
C:\Data\Company\<folder2>
& more

I want to archive this sub-folders to a new folder named Archived in C:\Data\Company with individual folders archived inside it.

C:\Data\Company\Archived\folder1.rar
C:\Data\Company\Archived\folder2.rar

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Archive Folders Winrar

#2 Post by Squashman » 20 Jan 2014 12:52

I don't have Winrar so you will have to supply that command.

Code: Select all

@echo off
pushd C:\Data

For /F "delims=" %%G IN ('dir /ad /b') do (
     pushd "%%G"
     For /F "delims=" %%H IN ('dir /ad /b ^| find /V "Archived"') do (
     winrar command here. %%H will be the folder you want to backup.
     )
)


I don't know the command line switches but it should look something like
rar a -r "..\Archived\%%H.rar" "%%H"

foncesa
Posts: 42
Joined: 12 Sep 2013 00:09

Re: Archive Folders Winrar

#3 Post by foncesa » 21 Jan 2014 01:47

Hi,
Thanks squashman for reply, But this codes compress the folder and sub-folders to Archived folder, instead of this i wanted to have the individual sub-folders to get archived and saved to Archived.

Like this:
C:\Data\Company\Archived\folder1.rar
C:\Data\Company\Archived\folder2.rar

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Archive Folders Winrar

#4 Post by Squashman » 21 Jan 2014 07:42

Like I said. I don't use Winrar and I don't have Winrar. You will have to lookup the correct syntax for the Winrar command.

If you can tell me what is ending up in the Archived Folder I might be able to help you troubleshoot it but without seeing what the script is outputting I really can't do much for you.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Archive Folders Winrar

#5 Post by Squashman » 21 Jan 2014 09:17

Ok. My fault. I forgot the POPD.
I also changed the RAR command to use the absolute path instead of the relative path.

Code: Select all

@echo off
pushd C:\Data

For /F "delims=" %%G IN ('dir /ad /b') do (
   pushd "%%G"
   For /F "delims=" %%H IN ('dir /ad /b ^| find /V "Archived"') do (
   rar a -r "%%~dpHArchived\%%H.rar" "%%H"
   )
   POPD
)
popd

foncesa
Posts: 42
Joined: 12 Sep 2013 00:09

Re: Archive Folders Winrar

#6 Post by foncesa » 21 Jan 2014 12:23

Hi,

Thanks Squashman. Its working.

Thanks

foncesa
Posts: 42
Joined: 12 Sep 2013 00:09

Re: Archive Folders Winrar

#7 Post by foncesa » 28 Jan 2014 13:03

Hi,

Sorry to restart the thread.

I need a small change if its possible the newly created .rar files are created and saved at C:\Data\Archived
instead be created & saved at D:\Backup\data.
I will be highly thankful.

Thanks

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Archive Folders Winrar

#8 Post by Squashman » 28 Jan 2014 17:54

Well this tells me you took the fish and didn't bother to learn how to fish. If you understand the syntax of the winrar command you should know what to change in that one line of code. At least make an attempt.

Post Reply