Avatar of Saggi
Saggi
 asked on

MS-Dos Script

I want to do the following
1. To create a directory structure C:\Projects\Application\Release.
2. Read a txt file version.txt (Ex: C:\Application\version.txt) which contains version number ex: 4.4.1
and create a directory with 4.4.1 under "C:\Projects\Application\Release" so the full path will be "C:\Projects\Application\Release\4.4.1"
3. Create a folder with current date (MM-DD-YYY) under "C:\Projects\Application\Release\4.4.1" finally it should create folder stucture like
 "C:\Projects\Application\Release\4.4.1\09-07-2010".
Microsoft DOS

Avatar of undefined
Last Comment
Ben Personick (Previously QCubed)

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Steve Knight

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ben Personick (Previously QCubed)


Saggi,  This is doable under batch, but I need to know what region your system runs in.  I will set the Date using North America Regional format, your date format may be different, if it is not comming out Correctly type "Echo %Date%" Also there may be a typo as I'm typing this on my BB. One additional note, I am formatting the date as you requested, but you should consider changing this to ISO standard (YYYY-MM-DD) for proper sorting of folders on a computer.

SET "RDir=C:\Projects\Application\Release"
SET "VTxt=C:\Application\version.txt"
FOR /F %%V IN ('Type "%VTxt%"') DO SET "VNum=%%V"
FOR /F "Tokens=2" %%D IN (%Date:/=-%) DO SET "RDate=%%D"
MD "%RDir%\%VNum%\%RDate%"
Saggi

ASKER
Thans Steve for quick response.
Looks like its working -:)

can you explain me once the below statements:
1. REM Get Date (purpose and use of it)
2. for /f "tokens=1" %%a in ('cscript //nologo "%temp%\dateparts.vbs"') do (set mmddyy=%%a) (what does /f, tokens, (' ') etc..)
3 ... Release 2>NUL (Redirecting to NUL what is pupose of 2)
Steve Knight

Of course.

1. REM is just a remark or comment

2. for command is powerful command that can read from directory listings, other files etc a line at a time.  see for/? for some good info.  In this case it sayas to read the output of the cscript command which is running the temporary vbscript (see article I linked to).  You can spliteach line up, e.g. at commas space etc into different tokens so this is just saying to return the first token.

3. 2> means redirect any error ouput to nul, ie. nowhere.  You have 1> and 2> for standard ouput (STDOUT) and errors (STDERR) but > is normally written as >.

Got to go now sorry, back later if needed!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Saggi

ASKER
QCubed,
Looks simple I tried but date folder is not getting created.
Ben Personick (Previously QCubed)

Your date is likely not in the North American Regional format.  As I mentioned I am assuming that format and if the folder is not created I'd like you to run ECHO "%Date%" at the command line, were you able to do this as I requested?

  Lol looks like Dragon totally sniped the Q while I was typing up mine on my BB on my way in to work this AM.
Steve Knight

Sorry Qcubed, it was posted an hour before and within 20 mins or so of the q post (and with wriggly baby helping onlap today....
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ben Personick (Previously QCubed)

lol, it's all good man. :-)
Steve Knight

Haha, know the feeling Iused to commute to Birmingham on the train for a while and then realised I'd just spent typing in the bizarre combinations of symbols etc. required for complex batch file with my Windows Mobile at the time...
Ben Personick (Previously QCubed)


Hahaha!  Gives you something to do anyway. ^^

I try to keep tabs on the Work BB, since my WinMo personal phone is still OOC for the time being.

I got a couple accepted answers off my BB posts too, so that is bonus.  But, like right now I am in a meeting, and I can quickly check Question info and respond if necessary.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Saggi

ASKER
QCubed:
I tried ECHO "%Date%" at the command line it works: "Wed 09/08/2010"
Iam in IST (Indian stanadard time).
SOLUTION
Ben Personick (Previously QCubed)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Steve Knight

Thanks, glad it helped....
Steve
Ben Personick (Previously QCubed)

hey thanks for the points, glad I could help out! =)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.