Retrieving filenames and inputting into another bat file?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Kev_NZ
Posts: 3
Joined: 19 Feb 2009 20:50

Retrieving filenames and inputting into another bat file?

#1 Post by Kev_NZ » 19 Feb 2009 21:18

Hey guys,

I'm new to batch files and I'm really stuck!

I've been put in charge of automating the backing up and restoring of some interbase databases at work. It's hard!

Here's my situation:

There are a few databases in this directory:

C:\MT32\data\

Eg, C:\MT32\data\database1.IB, database2.IB, database3.IB, database4.IB, etc...

I NEED 2 BATCH FILES!

The first bat file will search the directory where the databases are located, retrieve the filename of the first database, and input that into a few commands in a second bat file. Then repeat the process for the second database, and third database, and fourth, etc...

Here is what the main part of my second bat file looks like:

"C:\Program Files\Borland\InterBase\bin\gbak" -B -USER SYSDBA -PASSWORD masterkey -y "C:\MT32\GBAK Backup\FILENAME.log" "C:\MT32\data\FILENAME.IB" "C:\MT32\GBAK Backup\FILENAME.GBK"

So for my first bat file, what command will I use to retrieve the filenames of the databases and input them into the red highlighted sections of the second bat file?

I've tried plaving around with the FOR IN () DO COMMAND but no joy.

I would greatly appreciate any help on this matter.

Rock on
-Kev

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#2 Post by RElliott63 » 20 Feb 2009 08:22

You could try something like ...

Code: Select all

SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

For /F "Delims=" %%F in ('Dir /B \MT32\Data\Database*.IB') Do (
   Set "f=%%~nF"
   Call :BackupFiles !f!
)

:BackupFiles
"C:\Program Files\Borland\InterBase\bin\gbak" -B -USER SYSDBA -PASSWORD masterkey -y "C:\MT32\GBAK Backup\%1.log" "C:\MT32\data\%1.IB" "C:\MT32\GBAK Backup\%1.GBK"

Goto:EOF


That way you could do it all in ONE batch file.

**Just a suggestion, not tested**

-Rick

Kev_NZ
Posts: 3
Joined: 19 Feb 2009 20:50

#3 Post by Kev_NZ » 22 Feb 2009 21:38

Rick,

You are a legend!!!

The script works, though it does create a mystery file named ".log" which kinda screws up the flow of the script!

But none-the-less, the code you gave me works, and you have given me a very strong starting point.

Thank you very, very, very much.

Have a good one :)

Kev_NZ
Posts: 3
Joined: 19 Feb 2009 20:50

#4 Post by Kev_NZ » 23 Feb 2009 16:01

I just thought I would provide an update on this.

This code worked perfectly for me when I split it up into TWO batch files.

To be precise:

BAT FILE 1
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

For /F "Delims=" %%F in ('Dir /B \MT32\Data\Database*.IB') Do (
Set "f=%%~nF"
Call BAT FILE 2 !f!
)


BAT FILE 2
"C:\Program Files\Borland\InterBase\bin\gbak" -B -USER SYSDBA -PASSWORD masterkey -y "C:\MT32\GBAK Backup\%1.log" "C:\MT32\data\%1.IB" "C:\MT32\GBAK Backup\%1.GBK"

Goto:EOF


Again, I would like to express my deepest thanks to Rick! Thanks mate :)

Post Reply