Solved

WinRar Command line help

Posted on 2007-11-29
7
17,873 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
  • 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Good afternoon all, We are running a VM infrastructure on a clustered ESX environment with two DELL R710's.  One of our IT Application Support Engineers contacted me and asked if it was possible to extend the partition of a certain Windows 2003 S…
I wrote an article (http://www.experts-exchange.com/articles/2245/Anti-rootkit-software.html) some time ago with a reference to nLite  (http://www.nliteos.com/)slipstreaming software.  I recently changed that link to point to NTLite (https://www.ntl…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now