Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch Script question 1

Status
Not open for further replies.

inforeqd

Technical User
Jan 8, 2001
95
US
Is there a way that I can "awk" a dos command for a certain value? I'm trying to setup some way of doing a
call to date /t .. then getting the value of it into the format of MMDDYYYY and then have the script cd to that directory. Maybe this is too hard for a simple BATCH script? Not really sure because I never use Windows, in Unix/Linux this is a piece of cake to do in a shell script.

Any help would be really great.

tks
info
 
Not the easiest thing (have to output the command to a variable and then format it with some string concats).

Lucky for you, I have a script that does exactly that :)

for /f "tokens=2" %%a in ('date /t') do set zdate=%%a
set zdate=%zdate:/=%
set zdate=%zdate:~4,4%%zdate:~0,4%

You can then pull zdate into a mkdir command, or cd command, depending on what you're attempting. You don't have to use any quotes or & with a DOS script-just use the %var_name% in the middle of a string.
 
Jim, thanks a bunch, I did some searches before posting but it seems that the forum proves true again.

Thanks alot
inforeq
 
No problem. If you want to get into some more advanced (and easier code!) in Windows, check out some resources on Windows Script Host. Easy access to WMI to access just about any control/object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top