bat file help

B

bobloblian

Hi:
This group has been very helpful to me before, just to let you know its
been very much appreciated :)
Being familiar with bash scripting in a linux environment, I recently
waded into the world of writing a bat script for windows, I needed a
way to do a customized and fairly interaction-free back up on a windows
box to a DVD burner. I discovered that nero had a command line utility
and got it working fine so that within a double click and 3 or 4
keyboard strokes, selected types of backups can be done. Very easy for
the end user, as was required, in comparison to using the nero gui
interface. But then the number of files that needed to be backed up
increased dramatically, such that I can no longer fit it all onto one
DVD. In this respect, I need that script to be able to eject the
current DVD and ask for a new one. The nero DVD burning command line
does not have an argument that allows this to happen, so I got to
poking around for another way to do this.
The best solution I can come up with for the time being is to build
into the script a variable that allows me to keep track of how much
data is about to be written at once. By copying the files to be
written to a directory, and keeping track of the size of the directory,
I would be able to stop putting files into it and write them, eject the
disc, have the user put in a new disc and press a key to trash the
directory and do the same with the next set of data. I have found a
utility called diruse that will report the size of the directory for
me, but I am unclear as to how to take the portion of the output I need
and put it into a variable.
The output of diruse is to give the size in bytes (or MB or whatever),
then the number of files, then some text. I want to just put the size
field into a variable, but I am not sure how to extract just that
number from the output. In linux, I would use the cut command, but if
such a thing exists in the dos command structure, I cannot find it.
I am hoping someone has some idea of how I might proceed here, either
by showing me how to extract something from the output of diruse, or by
showing me another path that might do the same thing. As always, any
opinions are greatfully appreciated :)
 
P

Pegasus \(MVP\)

bobloblian said:
Hi:
This group has been very helpful to me before, just to let you know its
been very much appreciated :)
Being familiar with bash scripting in a linux environment, I recently
waded into the world of writing a bat script for windows, I needed a
way to do a customized and fairly interaction-free back up on a windows
box to a DVD burner. I discovered that nero had a command line utility
and got it working fine so that within a double click and 3 or 4
keyboard strokes, selected types of backups can be done. Very easy for
the end user, as was required, in comparison to using the nero gui
interface. But then the number of files that needed to be backed up
increased dramatically, such that I can no longer fit it all onto one
DVD. In this respect, I need that script to be able to eject the
current DVD and ask for a new one. The nero DVD burning command line
does not have an argument that allows this to happen, so I got to
poking around for another way to do this.
The best solution I can come up with for the time being is to build
into the script a variable that allows me to keep track of how much
data is about to be written at once. By copying the files to be
written to a directory, and keeping track of the size of the directory,
I would be able to stop putting files into it and write them, eject the
disc, have the user put in a new disc and press a key to trash the
directory and do the same with the next set of data. I have found a
utility called diruse that will report the size of the directory for
me, but I am unclear as to how to take the portion of the output I need
and put it into a variable.
The output of diruse is to give the size in bytes (or MB or whatever),
then the number of files, then some text. I want to just put the size
field into a variable, but I am not sure how to extract just that
number from the output. In linux, I would use the cut command, but if
such a thing exists in the dos command structure, I cannot find it.
I am hoping someone has some idea of how I might proceed here, either
by showing me how to extract something from the output of diruse, or by
showing me another path that might do the same thing. As always, any
opinions are greatfully appreciated :)

The mixed script/batch environment you intend to create is feasible
but it violates the KISS principle. Much better to do it all in Nero.
Here is a sample:
;-----------------------------------------------------------------
; Script file for nerocmd.exe
;
; 2.1.2005 Pegasus
;-----------------------------------------------------------------
--write
--real
--drivename G
--speed 32
--disable_eject
;--speedtest

;Specify a label of up to 16 chars. Embedded spaces are OK.
--iso "$Date$"
--enable_abort
--underrun_prot
--create_iso_fs
--recursive

; The "close session" statement allows for multi-session recording.
; Without it, the disk is closed after the first recording. With
; it, data can be added. Only the latest session is visible.
--Close_Session

; List of folders to be burnt.
; Note: If a single file in one of them is locked then the whole burn
process will fail.
d:\Data\Ledger
d:\Data\HSoft
d:\Data\Documents
d:\Data\Backup\PeterDesktop

Here is what you could do:

@echo off
set local enabledelayedexpansion
:: Set the capacity of the DVD (in MBytes)
set capacity=4000000
::prime the nero script
copy /y c:\scripts\template.scr c:\scripts\nero.scr
:: Navigate to the folder where your data resides
cd /d d:\Data
:: Prime the counter used to accumulate folder sizes
set Space=0
:: Process each folder in turn
for /d %%a in (*.*) do (
:: Find out the size of one subfolder
for /F "tokens=3" %%a in ('dir /s /-c ^| find /i "file(s)"') do set
curr=%%a
:: Turn bytes into kBytes
set /a curr=!curr! / 1000
:: Add it to the accumulator
set /a Space=%Space% + !curr!
:: Will it still fit on one DVD?
if !Space! GTR %capacity% (
:: No, it won't. Burn a DVD!
call nerocmd . . .
:: Reset the space counter
set Space=0
::prime the nero script
copy /y c:\scripts\template.scr c:\scripts\nero.scr
echo Please insert a new DVD!
echo.
echo Press the Space bar when ready!
pause > nul
)
:: Add the current folder to the Nero script
echo %%a >> c:\scripts\nero.scr
)
if %Space% GTR 0 call nerocmd . . .
endlocal

The same thing in pseudo-code:
1. Prepare a nero script with no folders specified.
2. Add the size of the current subfolder to the space counter.
3. If SpaceCount < capacity, add the current subfolder name
to the nero script. If not, goto 6.
4. Move to the next folder.
5. Goto 2.
6. Burn what's in the script.
7. Goto 1

Note that this method does NOT require any folders to be
copied to auxiliary folders.
 
B

bobloblian

Pegasus said:
The mixed script/batch environment you intend to create is feasible
but it violates the KISS principle. Much better to do it all in Nero.
Here is a sample:
;-----------------------------------------------------------------
; Script file for nerocmd.exe
;
; 2.1.2005 Pegasus
;-----------------------------------------------------------------
--write
--real
--drivename G
--speed 32
--disable_eject
;--speedtest

;Specify a label of up to 16 chars. Embedded spaces are OK.
--iso "$Date$"
--enable_abort
--underrun_prot
--create_iso_fs
--recursive

; The "close session" statement allows for multi-session recording.
; Without it, the disk is closed after the first recording. With
; it, data can be added. Only the latest session is visible.
--Close_Session

; List of folders to be burnt.
; Note: If a single file in one of them is locked then the whole burn
process will fail.
d:\Data\Ledger
d:\Data\HSoft
d:\Data\Documents
d:\Data\Backup\PeterDesktop

Here is what you could do:

@echo off
set local enabledelayedexpansion
:: Set the capacity of the DVD (in MBytes)
set capacity=4000000
::prime the nero script
copy /y c:\scripts\template.scr c:\scripts\nero.scr
:: Navigate to the folder where your data resides
cd /d d:\Data
:: Prime the counter used to accumulate folder sizes
set Space=0
:: Process each folder in turn
for /d %%a in (*.*) do (
:: Find out the size of one subfolder
for /F "tokens=3" %%a in ('dir /s /-c ^| find /i "file(s)"') do set
curr=%%a
:: Turn bytes into kBytes
set /a curr=!curr! / 1000
:: Add it to the accumulator
set /a Space=%Space% + !curr!
:: Will it still fit on one DVD?
if !Space! GTR %capacity% (
:: No, it won't. Burn a DVD!
call nerocmd . . .
:: Reset the space counter
set Space=0
::prime the nero script
copy /y c:\scripts\template.scr c:\scripts\nero.scr
echo Please insert a new DVD!
echo.
echo Press the Space bar when ready!
pause > nul
)
:: Add the current folder to the Nero script
echo %%a >> c:\scripts\nero.scr
)
if %Space% GTR 0 call nerocmd . . .
endlocal

The same thing in pseudo-code:
1. Prepare a nero script with no folders specified.
2. Add the size of the current subfolder to the space counter.
3. If SpaceCount < capacity, add the current subfolder name
to the nero script. If not, goto 6.
4. Move to the next folder.
5. Goto 2.
6. Burn what's in the script.
7. Goto 1

Note that this method does NOT require any folders to be
copied to auxiliary folders.

Thank you very kindly, you have not only shown me a better way to do
it, but shown me the for /f, which seems to be what I was looking for
originally :) thanks again :)
 
P

Pegasus \(MVP\)

bobloblian said:
Thank you very kindly, you have not only shown me a better way to do
it, but shown me the for /f, which seems to be what I was looking for
originally :) thanks again :)

Thanks for the feedback. I now realise that the first version of
my batch file contains a logical error - it calculate an incorrect
value for %Space% on the second and subsequent CDs.
Here is the amended version:

@echo off
set local enabledelayedexpansion
set capacity=4000000
copy /y c:\scripts\template.scr c:\scripts\nero.scr
cd /d d:\Data
set Space=0
for /d %%a in (*.*) do (
for /F "tokens=3" %%a in ('dir /s /-c ^| find /i "file(s)"') do set
curr=%%a
set /a curr=!curr! / 1000
set /a Space=%Space% + !curr!
if !Space! GTR %capacity% (
call nerocmd . . .
set Space=!curr!
copy /y c:\scripts\template.scr c:\scripts\nero.scr
echo Please insert a new DVD!
echo.
echo Press the Space bar when ready!
pause > nul
)
echo %%a >> c:\scripts\nero.scr
)
if %Space% GTR 0 call nerocmd . . .
endlocal

An overall comment: I'm not fond of backing up data to CDs/
DVDs. The process is relatively complex and therefore subject
to errors and failures. Furthermore, I am underimpressed with
the long term stability of burnt CDs/DVDs. These days I
mostly use 2.5" disks in external USB cases. They don't cost
much, they have a much greater capacity than DVDs and the
backup/restore commands are very simple.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top