Solved

WinRar Command line help

Posted on 2007-11-29
7
17,906 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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.

770 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