Solved

WinRar Command line help

Posted on 2007-11-29
7
17,918 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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