Announcement

Collapse
No announcement yet.

script to create folder with date format

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • script to create folder with date format

    Hi,

    I have a script that needs runs. I would like to reate a folder with the current date in the format of dd-mm-yyy or ddmmyyyy. I am using the following in my script but it generates an error of:

    1* was unexpected at this time.
    C:\Documents and Settings\phillipj>FOR /F ˘TOKENS=1* DELIMS= ÷ %A IN (ĂDATE/TĂ)
    DO SET CDATE=%B

    My script is:
    Code:
    @echo on
    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=%dd%%mm%%yyyy%
    md C:\test\%date%
    end


    Any ideas what i am doing wrong?

    Thanks
    Last edited by Rems; 8th January 2010, 12:40.

  • #2
    Re: script to create folder with date format

    Originally posted by phill View Post
    I would like to reate a folder with the current date in the format of dd-mm-yyy or ddmmyyyy.
    Use variable extension substrings. %date% contains the current date, which you can print via typing echo %date% into a command prompt. :~s,c syntax is used to extract a substring. Specify the start point (0 based index) and count of characters to be extracted. The exact values depend on your system locale, as date formats are not universal.

    In my Finnish system the date is pe 08.01.2010. So,

    Code:
    set strDate=%date:~3,2%%date:~6,2%%date:~9,4%
    will get two chars from index 3 (4th char) (0, two from index 6(01) and four from index 9(2010). Your mileage may vary.

    -vP

    Comment


    • #3
      Re: script to create folder with date format

      Make sure "straight quotes" (whether single quote signs or double quote signs) are used in the batch, don't use curly quotes.
      Also note that DATE is a reserved variable name.

      Code:
      @echo off
      
      for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
         for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
           (set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yyyy=%%p)))
      
      Set d=%yyyy%%mm%%dd%
      
      echo date (yyyymmdd): %d%
      pause
      \Rems
      Last edited by Rems; 8th January 2010, 12:41.

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment

      Working...
      X