Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



mkdir with date

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 15-03-2007
tom.henricksen@gmail.com
 
Posts: n/a
mkdir with date

This script works

echo off
@REM Seamonkey's quick date batch (MMDDYYYY format)
@REM Setups %date variable
@REM First parses month, day, and year into mm , dd, yyyy formats and
then combines to be MMDDYYYY

FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%
%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%yyyy%%mm%%dd%

echo %date%

mkdir BEMRX-%date%
cd BEMRX-%date%
mkdir Source
mkdir CD

but I would to make the directory name the date then -BEMRX instead of
the way it is. When I try this
mkdir %date%-BEMRX
that makes two directories(one the date and one -BEMRX). Is there a
way to make that the name of the one
directory?
Thanks,
Tom


Reply With Quote
  #2  
Old 16-03-2007
Marty List
 
Posts: n/a
Re: mkdir with date


This line works fine for me:
mkdir %date%-BEMRX
it creates a single directory named "20070315-BEMRX". What is the format of
your %date%, is it the same as mine (YYYYMMDD)?

Also, %date% is a dynamic built-in variable. To avoid breaking other
scripts, you might want to use "SetLocal" in your script or use a different
variable name:

SET folderdate=%yyyy%%mm%%dd%

echo %folderdate%

mkdir %folderdate%-BEMRX


<tom.henricksen@gmail.com> wrote in message
news:1173967609.464689.23930@d57g2000hsg.googlegroups.com...
> This script works
>
> echo off
> @REM Seamonkey's quick date batch (MMDDYYYY format)
> @REM Setups %date variable
> @REM First parses month, day, and year into mm , dd, yyyy formats and
> then combines to be MMDDYYYY
>
> FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
> FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
> FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%
> %B
> FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
> SET date=%yyyy%%mm%%dd%
>
> echo %date%
>
> mkdir BEMRX-%date%
> cd BEMRX-%date%
> mkdir Source
> mkdir CD
>
> but I would to make the directory name the date then -BEMRX instead of
> the way it is. When I try this
> mkdir %date%-BEMRX
> that makes two directories(one the date and one -BEMRX). Is there a
> way to make that the name of the one
> directory?
> Thanks,
> Tom
>


Reply With Quote
  #3  
Old 16-03-2007
Michael Bednarek
 
Posts: n/a
Re: mkdir with date

On 15 Mar 2007 07:06:49 -0700, tom.henricksen@... wrote in
microsoft.public.windows.server.scripting:

>This script works
>
>echo off
>@REM Seamonkey's quick date batch (MMDDYYYY format)
>@REM Setups %date variable
>@REM First parses month, day, and year into mm , dd, yyyy formats and
>then combines to be MMDDYYYY
>
>FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
>FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
>FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%
>%B
>FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
>SET date=%yyyy%%mm%%dd%
>
>echo %date%
>
>mkdir BEMRX-%date%
>cd BEMRX-%date%
>mkdir Source
>mkdir CD
>
>but I would to make the directory name the date then -BEMRX instead of
>the way it is. When I try this
>mkdir %date%-BEMRX
>that makes two directories(one the date and one -BEMRX). Is there a
>way to make that the name of the one
>directory?


(I suspect your code creates a trailing space in %date%; try
echo %date%-BEMRX
and you should see what's going on.)

BUT, why so complicated? This does the same:
mkdir %date:/=%-BEMRX

(This works from CMD's command line; CMD requires different number of
%-signs in batch files; I forget exactly how - never use it.)

--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
Reply With Quote
  #4  
Old 17-03-2007
Steven
 
Posts: n/a
Re: mkdir with date

echo %date:/=% returns "Fri 03162007" for me, how do you remove the first 4
letters and still remove the /'s?

I tried adding "~4" after the colon but couldn't get the output I was
looking for.
example %date:~4% returns "03/16/2007", but I cannot find a way to also
include the /= to remove the /'s, any ideas? I suppose I could just do it
in two steps using a temporary variable but It'd be nice to not have to.

note: "~x,y" skips x characters and grabs y characters, if ",y" is not
specified, returns all remaining characters

"Michael Bednarek" <ROT13-zo@gtz.pbz.nh> wrote in message
news:k48kv2p7jd6f2mg2pgpv3fqg08ab7qkbdu@4ax.com...
> On 15 Mar 2007 07:06:49 -0700, tom.henricksen@... wrote in
> microsoft.public.windows.server.scripting:
>
>>This script works
>>
>>echo off
>>@REM Seamonkey's quick date batch (MMDDYYYY format)
>>@REM Setups %date variable
>>@REM First parses month, day, and year into mm , dd, yyyy formats and
>>then combines to be MMDDYYYY
>>
>>FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
>>FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
>>FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%
>>%B
>>FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
>>SET date=%yyyy%%mm%%dd%
>>
>>echo %date%
>>
>>mkdir BEMRX-%date%
>>cd BEMRX-%date%
>>mkdir Source
>>mkdir CD
>>
>>but I would to make the directory name the date then -BEMRX instead of
>>the way it is. When I try this
>>mkdir %date%-BEMRX
>>that makes two directories(one the date and one -BEMRX). Is there a
>>way to make that the name of the one
>>directory?

>
> (I suspect your code creates a trailing space in %date%; try
> echo %date%-BEMRX
> and you should see what's going on.)
>
> BUT, why so complicated? This does the same:
> mkdir %date:/=%-BEMRX
>
> (This works from CMD's command line; CMD requires different number of
> %-signs in batch files; I forget exactly how - never use it.)
>
> --
> Michael Bednarek http://mbednarek.com/ "POST NO BILLS"



Reply With Quote
  #5  
Old 17-03-2007
Michael Bednarek
 
Posts: n/a
Re: mkdir with date

On Fri, 16 Mar 2007 13:09:04 -0700, Steven wrote in
microsoft.public.windows.server.scripting:

>echo %date:/=% returns "Fri 03162007" for me, how do you remove the first 4
>letters and still remove the /'s?
>
>I tried adding "~4" after the colon but couldn't get the output I was
>looking for.
>example %date:~4% returns "03/16/2007", but I cannot find a way to also
>include the /= to remove the /'s, any ideas? I suppose I could just do it
>in two steps using a temporary variable but It'd be nice to not have to.
>
>note: "~x,y" skips x characters and grabs y characters, if ",y" is not
>specified, returns all remaining characters

[snip]

CMD's environment variable DATE seems to be governed by Windows' "Short
date format". I suppose one could use a command line tool (REG.EXE) to
manipulate the registry on the fly to specify a suitable format; this
usually fails because a direct registry manipulation is not broadcast to
other applications.

The only truly generic method needs a language which provides access to
the elements which constitute a date; VBS/JS/4NT spring to mind.

--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "mkdir with date"
Thread Thread Starter Forum Replies Last Post
Baseline Column Date automatically updates Finish Date Adam 1980 Microsoft Project 3 18-05-2011 06:08 PM
Implementation of mkdir() : C Agustíne Software Development 4 02-02-2010 06:16 PM
Mkdir with variable space Kingfisher Software Development 5 19-12-2009 11:55 AM
Error mkdir() in PHP GlassFish Software Development 3 28-11-2009 10:33 AM
Changing start date and creating formula for finish date stringse Microsoft Project 1 11-09-2006 01:13 PM


All times are GMT +5.5. The time now is 01:06 AM.