DOS scripting problem - need help!

mud

Member
Oct 24, 2000
49
0
0
I'm trying to backup some files every night using the DOS console with pkzip under Win2k/XP. I'd like to automatically generate zip file names using the date. Is this feasible using simple DOS scripting?

Here is one of my ideas so far. The DOS command "date /t" outputs "Wed 02/20/2002".
I'd like to store this output in a variable, concatenate my own string to
it, then use it as an argument in pkzip. The following is the pseudocode:

VARIABLE = output of "date /t" // should store "Wed 02/20/2002"
VARIABLE = VARIABLE + "Database" // should store "Wed 02/20/2002Database"
pkzip25.exe -add -nofix -recurse -path=relative c:\shine\backup\VARIABLE
n:\database\*.*
// should create "Wed 02/20/2002Database.zip" in location c:\shine\backup\.

Is this even remotely possible in DOS scripting?

 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
Here is an idea using two batch files (don't sue me if it does not work ;-) )

1.bat:

echo pkzip25.exe -add -nofix -recurse -path=relative "c:\shine\backup\ > c:\2.bat
date /t >> c:\2.bat
echo Database.zip" n:\database\*.* >> c:\2.bat
call c:\2.bat

Lemme know if it works. pkzip might choke on the filename with the date, though. You may have to use single quotes as well.

 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
No, it does not work.
First of all the quotes have to be removed anyway (forgot about that).
But then the problem is that you get newlines. Don't know a way around that right now.

So close and yet so far.
 

thornc

Golden Member
Nov 29, 2000
1,011
0
0
Try find the 4DOS(4NT) shell they have a lot more scripting features...

I think that with pure DOS this might not be possible... or perhaps try installing perl on that machine...
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
I would use windows scripting host/VBscript if you can. Here is some code that should hopefully work for you. Put it in a text file and give it an extension of .vbs. No promises it will work, but if you tweak it you can probebly get it to work. Check out http://msdn.microsoft.com/scripting/ for references on scripting.

Dim strDate, strFileName

'pull out the "/" character because files cannot have "/" in them
strDate = WeekDayName(WeekDay(Date()), true) & Replace(Date(), "/", "") 'strDate = Wed2202002
strFileName = strDate & "Database" 'strFileName = Wed2202002Database

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
'run pkzip25 and add parameters
WshShell.Run "pkzip25.exe -add -nofix -recurse -path=relative c:\shine\backup\" & strFileName & " n:\database\*.*"
'should create "Wed02202002Database.zip" in location c:\shine\backup\.

MsgBox "Done"

Set WshShell = Nothing
 

mud

Member
Oct 24, 2000
49
0
0

I was able to run the script!!! Now I just need to see if it runs on some other systems and learn more about VBScript so that I can fully customize the script for other scenarios.

KB: YOU ABSOLUTELY ROCK!!!! If you need anything at all, let me know! :D

RSMemphis: Thanks for the idea. Almost worked. :)
 

lordex

Member
Feb 7, 2002
133
0
0

If you are running NT/W2K, %DATE% is a predefined variable that always has the current time in it,
check out this piece I got by typing in "set /?":



<<
If Command Extensions are enabled, then there are several dynamic
environment variables that can be expanded but which don't show up in
the list of variables displayed by SET. These variable values are
computed dynamically each time the value of the variable is expanded.
If the user explicitly defines a variable with one of these names, then
that definition will override the dynamic one described below:
%CD% - expands to the current directory string.
%DATE% - expands to current date using same format as DATE command.
%TIME% - expands to current time using same format as TIME command.
%RANDOM% - expands to a random decimal number between 0 and 32767.
%ERRORLEVEL% - expands to the current ERRORLEVEL value
%CMDEXTVERSION% - expands to the current Command Processor Extensions
version number.
%CMDCMDLINE% - expands to the original command line that invoked the
Command Processor.
>>