Solved

WinRar Command line help

Posted on 2007-11-29
7
17,925 Views
Last Modified: 2013-12-01
OK, I want to compress certain files for about 80 users and rather than writing individual batch files for each person I just went and hid the folders of non-important files.

Now the problem I'm having is that WinRAR command line only seems to exlude hidden FILES, not folders. Which isn't really working for me, and I'd prefer to not hide all of thefiles. Is there a way to exclude hidden folders instead of files?? I know winZIP does it but well.....WinRAR is so much better.

Heres what my current test batch file looks like(E-mail is a hidden folder I want included)

c:\"program files"\WinRaR\WinRAR a -u -r -Eh c:\"UserData"\"Plist.rar" c:\"UserData"\Plist\*.*
c:\"program files"\WinRaR\WinRAR a -u -r -Eh c:\"UserData"\"Plist.rar" c:\"UserData"\Plist\E-mail\*.*

Open in new window

0
Comment
Question by:PCL3385
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:Barthax
ID: 20382407
The DOS "FOR /D" syntax will exclude the hidden directories for you - but that means WinRAR must be executed for each folder.  Below is a quick knocked-up batch file to perform the action.  It takes two parameters: the first is the rar file to which the files are to be archived to & the second is the user's directory.  At the moment, you will notice both of the FOR statements have an @echo to show what would commands would get run (better for testing).


SET DESTRAR=%1
SET USERDIR=%2
SET WINRAR="C:\Program Files\WinRAR\WinRAR.exe"
SET WINRARCMD=%WINRAR% a -u -r
 
REM Assumes the batch file is on the same drive as the folder
REM If not remove the REM from the next line & adjust the letter:
REM C:
CD %USERDIR%
 
REM Do all the files (only) in the root directory
FOR %%f in (*.*) DO @echo %WINRARCMD% %DESTRAR% %%f
 
REM Do all the directories which are visible
FOR /D %%f in (*) DO @echo %WINRARCMD% %DESTRAR% %%f\*.*

Open in new window

0
 

Author Comment

by:PCL3385
ID: 20383377
Ok first off Thanks A lot for the help.
Sadly though, I believe my DOS knowledge is a bit lacking since I don't really understand what all i need to replace with actually directories.

My batch files are not in the same directory as the folder, it's on the local computer. And the folders are on our main server.
So i suppose my new question is could I get an example with actual directories so i know what I have to replace. Thanks again
0
 
LVL 19

Accepted Solution

by:
Barthax earned 500 total points
ID: 20383481
How are you executing (or proposing to execute) the batch file - as that is key to how this batch file could work (i.e., I can adjust it to accomodate)?

I've modified the batch by wayof example and I've assumed that the data you want to back up is as your example.  I've also added the bit I forgot: the hidden E-mail subfolder. :)

Note that my original is more versatile as it takes parameters.  If you're not comfortable with the command line, that's fine & I'll concentrate on a double-click style solution. :)
SET DESTRAR="C:\UserData\Plist.rar"
SET USERDIR="C:\UserData\Plist"
SET WINRAR="C:\Program Files\WinRAR\WinRAR.exe"
SET WINRARCMD=%WINRAR% a -u -r
 
REM Assumes the batch file is on the same drive as the folder
REM If not remove the REM from the next line & adjust the letter:
C:
CD %USERDIR%
 
REM Do all the files (only) in the root directory
FOR %%f in (*.*) DO @echo %WINRARCMD% %DESTRAR% %%f
 
REM Do all the directories which are visible
FOR /D %%f in (*) DO @echo %WINRARCMD% %DESTRAR% %%f\*.*
 
%WINRARCMD% %DESTRAR% %%f\E-mail\*.*

Open in new window

0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 19

Expert Comment

by:Barthax
ID: 20383486
Bah, the following line:

%WINRARCMD% %DESTRAR% %%f\E-mail\*.*

(last line) should read:

%WINRARCMD% %DESTRAR% %USERDIR%\E-mail\*.*
0
 

Author Comment

by:PCL3385
ID: 20383643
I'm running straight from the batch file(it doesn't seem to work at command line though I am probably doing something wrong)
But the final product I will be running from Auto Task Manager.

One thing I forgot though those are not the actual directories merely test directories.

Here is the actual batch I was using, and the thing is, is that every user is in the 1 batch file.
Is that going to cause problems with this method?
c:\"program files"\WinRaR\WinRAR a -u -r -esh e:\"data files"\"User Data"\"Plist.rar" \\mglsrv1\"UserData"\Plist\*.*
c:\"program files"\WinRaR\WinRAR a -u -r -esh e:\"data files"\"User Data"\"Plist.rar" \\mglsrv1\"UserData"\Plist\E-mail\*.* 
 
c:\"program files"\WinRaR\WinRAR a -u -r -esh e:\"data files"\"User Data"\"Plist2.rar" \\mglsrv1\"UserData"\Plist2\*.*
c:\"program files"\WinRaR\WinRAR a -u -r -esh e:\"data files"\"User Data"\"Plist2.rar" \\mglsrv1\"UserData"\Plist2\E-mail\*.* 

Open in new window

0
 

Author Closing Comment

by:PCL3385
ID: 31411709
Very Good answer was just hard to understand because of my lack of DOS knowledge
0
 
LVL 19

Expert Comment

by:Barthax
ID: 20387657
Let's see if we can't get this working then. :)  If you have more then just the two directories, the add them onto the end of the SET USERS= line (with spaces between).

@ECHO OFF
SET USERS=Plist Plist2
SET DESTRAR=E:\data files\UserData\%1.rar
SET USERDIR=\\mglsrv1\UserData\%1
SET WINRAR="C:\Program Files\WinRAR\WinRAR.exe"
SET WINRARCMD=%WINRAR% a -u -r -esh

REM If nothing is supplied on the command line, do the workload from USERS
IF "%1" == "" FOR %%f in (%USERS%) DO CALL %0 %%f
REM If nothing is supplied on the command line, exit
IF "%1" == "" GOTO :EOF

REM Do all the files (only) in the root directory
ECHO Getting files in %USERDIR%
FOR %%f in (%USERDIR%\*.*) DO %WINRARCMD% "%DESTRAR%" "%%f"

ECHO Getting directories in %USERDIR%
REM Do all the directories which are visible
FOR /D %%f in (%USERDIR%\*) DO %WINRARCMD% "%DESTRAR%" "%%f\*.*"

ECHO Getting E-mail dir
%WINRARCMD% "%DESTRAR%" "%USERDIR%\E-mail\*.*"

:EOF
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while back when OPSMGR 2012 was released we were very excited about getting it into our environment and upgrading our 2007 implementation,  we started our planning and we then proceeded with our implementation. All went as planned & our system …
I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question