1.

Solve : Batch File Problems?

Answer»

I want to have the date in a file name, problem is that the date is done like this: mm/dd/yyyy. A file name can't have a "/' in it. Any ideas on hwo to overcome that?This is OS dependent.

Code: [Select]
for /f "tokens=1-4 delims=/ " %%a in ("%date%") do (
set mon=%%b
set day=%%c
set yyyy=%%d
)


Now that you have mon, day and yyyy, you can do what you want with them.

Hope this helps. Hey, I've got the same problem, but a different setup.

There is a number like this: X.XX

I need to take the FIRST X and set it as a variable and take the last two XS and set them as a variable.

This'll probably just be the same as the above solution, just with some tweaks, but I'm not SURE how to do it.

BTW, THANKS a lot for your help! What you suggested for my last problem fixed it perfectly! Thanks!Pretty much the same thing. You didn't mention where this X.XX was so I just picked a literal to give you an idea how it WORKS:

Code: [Select]
for /f "tokens=1-2 delims=." %%a in ("X.YZ") do (
set varA=%%a
set varB=%%b
)


Hope this helps. There are two files, each with a number in them. Should this code get those numbers and put them into their appropriate variables or am I doing it wrong?

Code: [Select]for /f %%a in (UserVersionmajor.txt) do (set MAJ=%%a)
for /f %%a in (UserVersionminor.txt) do (set MIN=%%a)You could try it and see. Your're not doing anything destructive, but yeah it should work. Sorry, the last code you gave me is what I need, but I'm getting the stuff out of a file, not just a regular string.Code: [Select]
for /f %%a in (UserVersionMajor.txt) do (
set maj=%%a
)
for /f %%a in (UserVersionMinor.txt) do (
set min=%%a
)


Quote

There are two files, each with a number in them


This works if and only if the first file contains a single record with the major version AND the second file contains a single record with the minor version. If not then you add complexity requiring IF statements to identify the record and to parse out the value you need.

DOS batch is not designed for low level record processing.

Good luck.


Discussion

No Comment Found