PC Review


Reply
Thread Tools Rate Thread

Array In Batch Script

 
 
jj@anti-exe.com
Guest
Posts: n/a
 
      27th Sep 2006
I'm trying to create a batch script for backups using rar.exe. What I'm
wanting to do is create a separate .rar for each directory.

Here's an example...
c:\test\filename1.ext
c:\test\filename2.ext
c:\test\directory1\filename1.ext
c:\test\directory2\filename1.ext
c:\test\directory2\filename2.ext
c:\test\directory2\filename3.ext
I want to have c:\test\*.*, c:\test\directory1\*.*, and
c:\test\directory2\*.* in 3 separate .rar's.

I was thinking that I could do it with (E-Mail Removed) (dir /B c:\test >
list.txt) but it doesn't make it create separate files. I'm thinking
that I need to do an array from list.txt or something, but I'm not sure
how. Honestly, I'm not sure if a batch file has the logic to even do
arrays.
JJ

 
Reply With Quote
 
 
 
 
Mark V
Guest
Posts: n/a
 
      28th Sep 2006
In microsoft.public.win2000.cmdprompt.admin wrote:

> I'm trying to create a batch script for backups using rar.exe.
> What I'm wanting to do is create a separate .rar for each
> directory.
>
> Here's an example...
> c:\test\filename1.ext
> c:\test\filename2.ext
> c:\test\directory1\filename1.ext
> c:\test\directory2\filename1.ext
> c:\test\directory2\filename2.ext
> c:\test\directory2\filename3.ext
> I want to have c:\test\*.*, c:\test\directory1\*.*, and
> c:\test\directory2\*.* in 3 separate .rar's.
>
> I was thinking that I could do it with (E-Mail Removed) (dir /B
> c:\test > list.txt) but it doesn't make it create separate
> files. I'm thinking that I need to do an array from list.txt or
> something, but I'm not sure how. Honestly, I'm not sure if a
> batch file has the logic to even do arrays.


Probably a FOR construct that "walks the tree" is a good approach to
use.
 
Reply With Quote
 
billious
Guest
Posts: n/a
 
      28th Sep 2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to create a batch script for backups using rar.exe. What I'm
> wanting to do is create a separate .rar for each directory.
>
> Here's an example...
> c:\test\filename1.ext
> c:\test\filename2.ext
> c:\test\directory1\filename1.ext
> c:\test\directory2\filename1.ext
> c:\test\directory2\filename2.ext
> c:\test\directory2\filename3.ext
> I want to have c:\test\*.*, c:\test\directory1\*.*, and
> c:\test\directory2\*.* in 3 separate .rar's.
>
> I was thinking that I could do it with (E-Mail Removed) (dir /B c:\test >
> list.txt) but it doesn't make it create separate files. I'm thinking
> that I need to do an array from list.txt or something, but I'm not sure
> how. Honestly, I'm not sure if a batch file has the logic to even do
> arrays.
> JJ
>


You appear very concerned with HOW, but light on the WHAT.

What would be the filenames generated?
Do you want a new file for each of the subdirectories found in the tree?

And since RAR is a third-party utility, best to specify the BASIC syntax
required. We don't need to know the compression switches, for instance - but
n@list... means nothing unless you are familiar with RAR - and my 1996
version doesn't appear to have an "n" switch.

NT4/2K/XP/2K3 (NT+ systems) are also discussed in alt.msdos.batch.nt.

----- batch begins -------
[1]@echo off
[2]setlocal enabledelayedexpansion
[3]for /r c:\106x %%i in (.) do set yfn=%%i&set yfn=!yfn:~3,-2!&set
yfn=!yfn:\=_!&ECHO RAR a "c:\destdir\!yfn!.rar" "%%i\*.*"
[4]goto :eof
------ batch ends --------

Lines start [number] - any lines not starting [number] have been wrapped
and should be rejoined. The [number] that starts the line should be removed

The ECHO keyword needs to be removed to activate the archiving.
It is there as a safety measure to show what the process WOULD do until
you have verified that it will do what you require

The label :eof is defined in NT+ to be end-of-file but MUST be expressed
as :eof

C:\106x... is my test directory. Modify to suit your directory as required.

This would generate filenames "test_dirname1_subdir1_subdir2.rar" in
c:\destdir for "C:\test\dirname1\subdir1\subdir2\*.*" as far as I read the
documentation. In the absence of more information (like perhaps, adding in
the run-date/time data) it's a way of creating an obvious link to the
original.

I've no idea whether RAR is happy with quoted pathnames or interprets
"pathname\.\*.*" correctly. For that reason, you should supply the syntax.

If you don't use silly directorynames (ie. you keep to alphamerics) then the
quotes may be omitted. If your pathnames contain spaces or special
characters, you'll probably need the quotes.


 
Reply With Quote
 
Jean Pierre Daviau
Guest
Posts: n/a
 
      23rd Oct 2006
If I may introduce myself.

for /r "C:\Documents and Settings\Jean Pierre\Bureau\destdir" %%i in (.) do
set yfn=%%i&set yfn=!yfn:~3,-2! & @echo "C:\!yfn!.zip"

"C:\:\Documents and Settings\Jean Pierre\Bureau\destd .zip"

I have a blank space here---------------------------->


 
Reply With Quote
 
Alexander Suhovey
Guest
Posts: n/a
 
      23rd Oct 2006
> -----Original Message-----
> From: Jean Pierre Daviau [private.php?do=newpm&u=]
> Posted At: Monday, October 23, 2006 6:29 PM
> Posted To: microsoft.public.win2000.cmdprompt.admin
> Conversation: Array In Batch Script
> Subject: Re: Array In Batch Script
>
>
> If I may introduce myself.
>
> for /r "C:\Documents and Settings\Jean Pierre\Bureau\destdir"
> %%i in (.) do
> set yfn=%%i&set yfn=!yfn:~3,-2! & @echo "C:\!yfn!.zip"
>
> "C:\:\Documents and Settings\Jean Pierre\Bureau\destd .zip"
>
> I have a blank space here---------------------------->
>



set yfn=%%i&set yfn=!yfn:~3,-2! & @echo "C:\!yfn!.zip"
That's where it came from-------^

Should be:

set yfn=%%i&set yfn=!yfn:~3,-2!& @echo "C:\!yfn!.zip"
No space here------------------^


--
Alexander Suhovey

 
Reply With Quote
 
Jean Pierre Daviau
Guest
Posts: n/a
 
      23rd Oct 2006
Thank you


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A script/batch to kill a batch file from scheduled tasks? Bogdan Windows XP Configuration 1 31st Jul 2009 06:05 AM
Array In Batch Script =?Utf-8?B?ZG91YmxlSg==?= Windows XP Security 1 27th Sep 2006 11:38 PM
batch script Miha Microsoft Windows 2000 7 15th Jun 2005 10:04 PM
batch script Miha Microsoft Windows 2000 Group Policy 7 15th Jun 2005 10:04 PM
batch script Miha Microsoft Windows 2000 RAS Routing 7 15th Jun 2005 10:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:30 PM.