Array In Batch Script

  • Thread starter Thread starter jj
  • Start date Start date
J

jj

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 address 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
 
In said:
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 address 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.
 
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 address 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.
 
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---------------------------->
 
-----Original Message-----
From: Jean Pierre Daviau [mailto:[email protected]]
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------------------^
 
Back
Top