Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MS-Dos Script

Posted on 2010-09-07
14
Medium Priority
?
629 Views
Last Modified: 2012-06-27
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".
0
Comment
Question by:Saggi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
14 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 1200 total points
ID: 33617246
See this for date code:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_1153-Using-dates-in-batch-files-scripts.html

This should do what you ask I think:

Steve

@echo off
mkdir C:\Projects\Application\Release 2>NUL
for /f "tokens=*" %%a in ('type C:\Projects\Application\version.txt') do (set vernum=%%a)
if "%vernum%"=="" (
  echo Unable to read version number
  pause
  exit /b
)
mkdir C:\Projects\Application\Release\%vernum% 2>NUL
REM Get Date
echo wscript.echo right(100+month(date),2) ^& "-" ^& right(100+day(date),2) ^& "-" ^& right(year(date),2) >"%temp%\dateparts.vbs"
for /f "tokens=1" %%a in ('cscript //nologo "%temp%\dateparts.vbs"') do (set mmddyy=%%a)
mkdir C:\Projects\Application\Release\%vernum%\%mmddyy% 2>NUL
echo Have created C:\Projects\Application\Release\%vernum%\%mmddyy%
0
 
LVL 14
ID: 33617697

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%"
0
 

Author Comment

by:Saggi
ID: 33617744
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)
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 43

Expert Comment

by:Steve Knight
ID: 33617874
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!
0
 

Author Comment

by:Saggi
ID: 33617925
QCubed,
Looks simple I tried but date folder is not getting created.
0
 
LVL 14
ID: 33619127
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.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33619302
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....
0
 
LVL 14
ID: 33619497
lol, it's all good man. :-)
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33620780
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...
0
 
LVL 14
ID: 33620941

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.
0
 

Author Comment

by:Saggi
ID: 33624390
QCubed:
I tried ECHO "%Date%" at the command line it works: "Wed 09/08/2010"
Iam in IST (Indian stanadard time).
0
 
LVL 14

Assisted Solution

by:Ben Personick (Previously QCubed)
Ben Personick (Previously QCubed) earned 800 total points
ID: 33628742
Hey Saggi, it was a VERY simple mistake I made while typing that out on my blackberry, I didn't put the double-quotes around the date.  I have added the quotes and everything works as expected now.

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%"

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33635130
Thanks, glad it helped....
Steve
0
 
LVL 14
ID: 33636550
hey thanks for the points, glad I could help out! =)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question