1.

Solve : Replace '/' char in a DOS Batch File variable?

Answer»

I have captured today's date into a DOS batch file variable (under XP) using :

SET FILENAME=%date%

Now I want to create a zip file using the returned date, but unfortunately under UK REGIONAL Settings the date is returned with forward slashes as SEPARATORS eg ‘25/01/06’ so I can't create a file with a '/' illegal character in it.

Anyone know how I can replace the '/' with a '-' (or a space) so that the variable CONTAINS '25-01-06' rather than '25/01/06'.

Then I'll be able to pass it to my Zip command :

c:\apps\winzip\wzzip -ex -rP -s %FILENAME%.zip c:\DATA2\*.*


Thanks
set filename=%filename:/=-%

will replace / against - in the variable filename

uliThank you, that worked perfectly.

The only odd thing is that my next command :

c:\apps\winzip\wzzip -ex -rP -s %FILENAME%.zip c:\data2\*.*

where the %filename% variable is used, produces this message :

Warning: no files were found for this pattern that match your selection criteria
: .zip

but then goes on to zip all the correct files. Formerly, when the user supplied the filename manually to the variable, this error didn't occur....



Discussion

No Comment Found