Jump to content

[DOS] Make Date 7 Time Folders from batch File


Recommended Posts

Sorry if this post: :blushing:

Other Post

Should have been placed in here but im kinda stuck now....any chance anyone of you programmers here could take a swift peek?? :}

Im trying to get the following a batch file to make the following directory structure...

C:\LOGS\**USERNAME**\**DATE (130105 formt will be good)**\**TIME (24h)**

Is this at all possible??

:unsure: 'Prepares to be shouted at'

thanks all,

SB

Link to comment
Share on other sites

  • 2 weeks later...

Actually batch should be enough.

Here is a simple batch (.cmd) example for date/time.

This will work only on Win2k/XP/2003.

European notation:

@Echo OFF
TITLE mdEU - Make directory with current date/time (EU notation)
REM mdEU.CMD
REM Make directory with current date/time in a given path
REM
REM -------------------------------------------------------------
IF %1.==. GoTo USAGE
Set CURRDATE=%TEMP%\CURRDATE.TMP
Set CURRTIME=%TEMP%\CURRTIME.TMP

DATE /T > %CURRDATE%
TIME /T > %CURRTIME%

Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYY=%%l%
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET MM=%%k%
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET DD=%%j%

Set PARSEARG="eol=; tokens=1,2,3* delims=:, "
For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k

Set NOW=%DD%_%MM%_%YYYY%_%HHMM%

Echo Make directory %1\%NOW% ?
Echo (Press Ctr+C to abort)

Pause
IF EXIST %1\%NOW% GOTO ERROR
IF NOT EXIST %1\%NOW% MD %1\%NOW%
CLS
IF EXIST %1\%NOW% ECHO Directory %1\%NOW% created successfully!
GoTo END

:USAGE
Echo ...no path specified... aborted!
Echo ********************************
Echo Usage: mdEU [PATH]
Echo ********************************
Echo Example: mdEU C: or mdEU C:\TEMP
Echo ********************************
Echo Makes a directory DD_MM_YYYY_HH.MM (EU notation)
Echo Where
Echo DD    = Day  
Echo MM    = Month (i.e. 01 for january)
Echo YYYY  = Year  (i.e. 2000)  
Echo HH.MM = Time

Pause
GoTo END

:ERROR
ECHO Directory %1\%NOW% already exists!
ECHO Execution aborted...try again in a minute!

:END
REM CLEARING USED VARIABLES AND TEMP FILES
IF EXIST %TEMP%\CURRDATE.TMP Del %TEMP%\CURRDATE.TMP
IF EXIST %TEMP%\CURRTIME.TMP Del %TEMP%\CURRTIME.TMP
SET CURRDATE=
SET CURRTIME=
SET YYYY=
SET PARSEARG=
SET MM=
SET DD=
SET HHMM=
SET NOW=
REM
TITLE Command Prompt

US notation:

@Echo OFF
TITLE mdUS - Make directory with current date/time (US notation)
REM mdUS.CMD
REM Make directory with current date/time in a given path
REM
REM -------------------------------------------------------------
IF %1.==. GoTo USAGE
Set CURRDATE=%TEMP%\CURRDATE.TMP
Set CURRTIME=%TEMP%\CURRTIME.TMP

DATE /T > %CURRDATE%
TIME /T > %CURRTIME%

Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYY=%%l%
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET MM=%%k%
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET DD=%%j%

Set PARSEARG="eol=; tokens=1,2,3* delims=:, "
For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k

Set NOW=%YYYY%_%MM%_%DD%_%HHMM%

Echo Make directory %1\%NOW% ?
Echo (Press Ctr+C to abort)

Pause
IF EXIST %1\%NOW% GOTO ERROR
IF NOT EXIST %1\%NOW% MD %1\%NOW%
CLS
IF EXIST %1\%NOW% ECHO Directory %1\%NOW% created successfully!
GoTo END

:USAGE
Echo ...no path specified... aborted!
Echo ********************************
Echo Usage: mdUS [PATH]
Echo ********************************
Echo Example: mdUS C: or mdUS C:\TEMP
Echo ********************************
Echo Makes a directory YYYY_MM_DD_HH.MM (US notation)
Echo Where
Echo YYYY  = Year  (i.e. 2000)
Echo MM    = Month (i.e. 01 for january)
Echo DD    = Day  
Echo HH.MM = Time

Pause
GoTo END

:ERROR
ECHO Directory %1\%NOW% already exists!
ECHO Execution aborted...try again in a minute!

:END
REM CLEARING USED VARIABLES AND TEMP FILES
IF EXIST %TEMP%\CURRDATE.TMP Del %TEMP%\CURRDATE.TMP
IF EXIST %TEMP%\CURRTIME.TMP Del %TEMP%\CURRTIME.TMP
SET CURRDATE=
SET CURRTIME=
SET YYYY=
SET PARSEARG=
SET MM=
SET DD=
SET HHMM=
SET NOW=
REM
TITLE Command Prompt

jaclaz

Link to comment
Share on other sites

This works too. (Win2K/XP)

set hour=%time:~0,2%
if "%hour:~0,1%"==" " set hour=0%time:~1,1%
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
set subfolder=%hour%_%time:~3,2%_%time:~6,2%
md c:\logs\%username%\%folder%\%subfolder%

If you want the date and time as the foldername you could use this:

set hour=%time:~0,2%
if "%hour:~0,1%"==" " set hour=0%time:~1,1%
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%_%time:~6,2%
md c:\logs\%username%\%folder%

Both are incomplete since I can't tell exactly what you are trying to do, but you should be able to figure out any additions you need.

I just happened to be driving by and saw you were looking for something I was trying to do a week ago, and with the help of a friend we put this together.

Hope it helps.

cheers

Link to comment
Share on other sites

  • 4 weeks later...

Here This Makes A Folder Based On date In This Format

03-01-2005

@echo off
cls
color F2
mode con: Cols=55 Lines=3
Title What Year Is It Test 2
NLSFUNC
SET D1=%date:~-4,10%
SET D2=%date:~7,-5%
SET D3=%date:~4,-8%
SET D4=%date:~0,-10%


if exist %D3%-%D2%-%D1% goto E1
if not exist %D3%-%D2%-%D1% goto W1

:W1
mkdir %D3%-%D2%-%D1%
echo.
echo Folder %D3%-%D2%-%D1% Was Made!
ping -n 3 127.0.0.1>nul
exit

:e1
echo.
echo Folder Was Already Made!
ping -n 3 127.0.0.1>nul

Link to comment
Share on other sites

  • 3 months later...

Sixpack,

The code you provided is exactly what I'm looking for except that I cannot get it to work - I end up with 2005-06-%D2%.

I'm afraid I know practically no DOS and I'm really just looking for the simplest way to call a file by the current date, in the format yyyymmdd.

I didn't understand the coding eg "~-4,10" so couldn't work it out for myself!

Can anyone help me?

Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

If you are in the UK with its default date and time format, you could use this one liner

if not exist "c:\logs\%username%\%date:~0,2%%date:~3,2%%date:~8,2%\%time:~0,2%%time:~3,2%" md "c:\logs\%username%\%date:~0,2%%date:~3,2%%date:~8,2%\%time:~0,2%%time:~3,2%"

<Edit>

If you want the format like this 06-07-2005\20-53, then use this one liner instead

if not exist "c:\logs\%username%\%date:/=-%\%time:~0,2%-%time:~3,2%" md "c:\logs\%username%\%date:/=-%\%time:~0,2%-%time:~3,2%"

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

This Is A Way To Do It In VBS

They all check for a folder Named By the date

If The folder is not there then it makes the folder named after date

If the folder is there then it makes a folder based on time instead.

One Line

This Line end at Approx 350 in the editor i was using.

If not CreateObject("Scripting.FileSystemObject").FolderExists(Year(Date) & "-" & Month(Date) & "-" & Day(Date)) Then CreateObject("Scripting.FileSystemObject").CreateFolder(Year(Date) & "-" & Month(Date) & "-" & Day(Date)) Else CreateObject("Scripting.FileSystemObject").CreateFolder(Hour(Time) & "-" & Minute(Time) & "-" & second(Time)) End If

2 Lines Using A Array

The Longest Line end at Approx 218 in the editor i was using.

Dim D_T : D_T = Array((Year(Date) & "-" & Month(Date) & "-" & Day(Date)),(Hour(Time) & "-" & Minute(Time) & "-" & second(Time)))

If not CreateObject("Scripting.FileSystemObject").FolderExists(D_T(0)) Then CreateObject("Scripting.FileSystemObject").CreateFolder(D_T(0)) Else CreateObject("Scripting.FileSystemObject").CreateFolder(D_T(1)) End If

3 Lines

The Longest Line end at Approx 215 in the editor i was using.

Dim Fld1 : Fld1 = (Year(Date) & "-" & Month(Date) & "-" & Day(Date))

Dim Fld2 : Fld2 = (Hour(Time) & "-" & Minute(Time) & "-" & second(Time))

If not CreateObject("Scripting.FileSystemObject").FolderExists(Fld1) Then CreateObject("Scripting.FileSystemObject").CreateFolder(Fld1) Else CreateObject("Scripting.FileSystemObject").CreateFolder(Fld2) End If

3 Lines Using A Array

The Longest Line end at Approx 100 in the editor i was using.

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")

Dim D_T : D_T = Array((Year(Date) & "-" & Month(Date) & "-" & Day(Date)),(Hour(Time) & "-" & Minute(Time) & "-" & second(Time)))

If not CreateObject("Scripting.FileSystemObject").FolderExists(D_T(0)) Then CreateObject("Scripting.FileSystemObject").CreateFolder(D_T(0)) Else CreateObject("Scripting.FileSystemObject").CreateFolder(D_T(1)) End If

4 Lines

The Longest Line end at Approx 95 in the editor i was using.

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")

Dim Fld1 : Fld1 = (Year(Date) & "-" & Month(Date) & "-" & Day(Date))

Dim Fld2 : Fld2 = (Hour(Time) & "-" & Minute(Time) & "-" & second(Time))

If not Fso.FolderExists(Fld1) Then Fso.CreateFolder(Fld1) Else Fso.CreateFolder(Fld2) End If

Here Is A One Line Cmd That make The One Line Vbs then

Makes The Folder.

This Line Of Code is approx 515 long in notepad.exe

echo off && CLS && Mode 55,3 && Color f2 && Title Gsm Cmd2Vbs ChkFolder &&  > %systemDrive%\CheckFolder.vbs Echo If not CreateObject("Scripting.FileSystemObject").FolderExists(Year(Date) ^& "-" ^& Month(Date) ^& "-" ^& Day(Date)) Then CreateObject("Scripting.FileSystemObject").CreateFolder(Year(Date) ^& "-" ^& Month(Date) ^& "-" ^& Day(Date)) Else CreateObject("Scripting.FileSystemObject").CreateFolder(Hour(Time) ^& "-" ^& Minute(Time) ^& "-" ^& second(Time)) End If && (start /w %systemDrive%\CheckFolder.vbs)

Redeit of the above I added a Completed message and where the folder will be made.

This Line Of Code is approx 595 long in notepad.exe

echo off && CLS && Mode 85,3 && Color f2 && Title Gsm Cmd2Vbs ChkFolder &&  > %systemDrive%\CheckFolder.vbs Echo If not CreateObject("Scripting.FileSystemObject").FolderExists(Year(Date) ^& "-" ^& Month(Date) ^& "-" ^& Day(Date)) Then CreateObject("Scripting.FileSystemObject").CreateFolder(Year(Date) ^& "-" ^& Month(Date) ^& "-" ^& Day(Date)) Else CreateObject("Scripting.FileSystemObject").CreateFolder(Hour(Time) ^& "-" ^& Minute(Time) ^& "-" ^& second(Time)) End If && (start /w %systemDrive%\CheckFolder.vbs) && Echo. && Echo Completed The Folder Are In %CD% && ping -n 4 127.0.0.1>nul

This One The Same As The Above But Now Names The Second Folder UserName And Time this one now deletes the vbs file it makes now

This Line Of Code is approx 665 long in notepad.exe

echo off && CLS && Mode 80,4 && Color f2 && Title Gsm Cmd2Vbs ChkFolder &&  > %systemDrive%\CheckFolder.vbs Echo If not CreateObject("Scripting.FileSystemObject").FolderExists(Year(Date) ^& "-" ^& Month(Date) ^& "-" ^& Day(Date)) Then CreateObject("Scripting.FileSystemObject").CreateFolder(Year(Date) ^& "-" ^& Month(Date) ^& "-" ^& Day(Date)) Else CreateObject("Scripting.FileSystemObject").CreateFolder("%UserName%" ^& Hour(Time) ^& "-" ^& Minute(Time) ^& "-" ^& second(Time)) End If && (start /w %systemDrive%\CheckFolder.vbs) && Echo. && Echo %UserName%,Completed The Folder Are In && Echo %CD% && ping -n 4 127.0.0.1>nul && Del %systemDrive%\CheckFolder.vbs

Edited by gunsmokingman
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...