# Solved: DOS Batch file help



## shavenlunatic (Aug 18, 2006)

Hi,

I am currently setting up a batch file to archive some stuff, but the file names relate to the date, now windows 2k returns the date (Day dd/mm/yyyy) with the DAY at the begginning, annoyingly, whereas windows xp purely returns the (dd/mm/yyyy) (which is fine)

I am using the following to save the file as the date (ddmmyyyy):

```
pkzip -rp c:\dbbackup\backup\%date:~-4,4%%date:~-7,2%%date:~0,2%.zip C:\dbbackup\backup\temp\*.* >> c:\dbbackup\log.txt
```
Is it possible to do the following?:

If windows = xp then
run the above line of code
else windows 2000
run an ammended line of code to take into account the extra 4 chars returned by the date command

Changing the actual line of code to compensate for the extra chars, but the actual if statement I would need has me lost, any ideas?

Thanks in advance (and i hope this makes some sense!!!)


----------



## Andraxion (Aug 6, 2006)

"If windows = xp then"

I think you have to call something previously to say whether it is Windows XP. Sorry I can't help more but I don't know anything about Batch files. =/


----------



## shavenlunatic (Aug 18, 2006)

yeah, "VER" returns the version, I just don't know how to use that return in the way I need to


----------



## JohnWill (Oct 19, 2002)

Have you considered some of the many batch file utilities? Simtel has a huge variety of them. Another way would be to use AutoIt and create a simple utility to do the O/S recognition, or the whole job.


----------



## ghostdog74 (Dec 7, 2005)

The date/time depends on the regional and language settings on your computer. Why not use a language that takes care of the time/date formatting for you?
Here's one in python:

```
>>> import os
>>> import time
>>> year,month,day = time.strftime("%Y %b %d", time.localtime()).split() #get yr,mth,day
>>> print year,month,day  
2006 Aug 20
>>> tempdir = os.path.join("c:\\","dbbackup","backup","temp","*.*")
>>> print tempdir
c:\dbbackup\backup\temp\*.*
>>> backupdir = os.path.join("c:\\","dbbackup","backup")
>>> print backupdir
c:\dbbackup\backup
>>> zipfile = os.path.join(tempdir, day+month+year+".zip")
>>> print zipfile
c:\dbbackup\backup\temp\20Aug2006.zip
>>> command = "pkzip -zp %s %s " %(zipfile,tempdir)
>>> print command
pkzip -zp c:\dbbackup\backup\temp\20Aug2006.zip c:\dbbackup\backup\temp\*.* 
>>> os.system(command)  #execute pkzip
```


----------



## shavenlunatic (Aug 18, 2006)

would be nice to have python but we can't have it on the systems  thanks for help thougth 

i might just end up running it in vba, was trying tio avoid it but i may have no choice


----------



## JohnWill (Oct 19, 2002)

AutoIt is a simple scripting language that will do the job. It can create an EXE file for the scripts, very handy. I use it for automating a number of tasks.


----------



## shavenlunatic (Aug 18, 2006)

sorted it... for anyones information who may need it:


```
@echo off
ver | find "XP" > nul
if errorlevel 1 goto machineIsNotXP
:XP
:
: run the XP code here
:
echo I may be running XP as I'm not running Windows 2000
:
goto end
:
:machineIsNotXP
:
: run the 2000 code here
:
echo I may be running 2000 as I'm not running Windows XP
:
:end
```
works a treat


----------



## JohnWill (Oct 19, 2002)

You can mark your own threads solved using the thread tools at the upper right of the screen.


----------



## shavenlunatic (Aug 18, 2006)

cool, will do, thought id share the wealth anyway


----------



## JohnWill (Oct 19, 2002)

We thank you for the feedback, always nice to have the solution posted with the issue. :up:


----------

