SilverBulletUK Posted January 25, 2005 Posted January 25, 2005 Sorry if this post: Other PostShould 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?? 'Prepares to be shouted at'thanks all,SB
dman Posted February 3, 2005 Posted February 3, 2005 you need to run a .vbs script to set up some enviornment variables first.at command prompt or from another batch file run:>runnow.vbs datepath.batdatepath.zip
jaclaz Posted February 4, 2005 Posted February 4, 2005 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 OFFTITLE mdEU - Make directory with current date/time (EU notation)REM mdEU.CMDREM Make directory with current date/time in a given pathREMREM -------------------------------------------------------------IF %1.==. GoTo USAGESet CURRDATE=%TEMP%\CURRDATE.TMPSet CURRTIME=%TEMP%\CURRTIME.TMPDATE /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%%kSet NOW=%DD%_%MM%_%YYYY%_%HHMM%Echo Make directory %1\%NOW% ?Echo (Press Ctr+C to abort)PauseIF EXIST %1\%NOW% GOTO ERRORIF NOT EXIST %1\%NOW% MD %1\%NOW%CLS IF EXIST %1\%NOW% ECHO Directory %1\%NOW% created successfully!GoTo END:USAGEEcho ...no path specified... aborted!Echo ********************************Echo Usage: mdEU [PATH]Echo ********************************Echo Example: mdEU C: or mdEU C:\TEMPEcho ********************************Echo Makes a directory DD_MM_YYYY_HH.MM (EU notation)Echo WhereEcho DD = Day Echo MM = Month (i.e. 01 for january)Echo YYYY = Year (i.e. 2000) Echo HH.MM = TimePauseGoTo END:ERRORECHO Directory %1\%NOW% already exists!ECHO Execution aborted...try again in a minute!:ENDREM CLEARING USED VARIABLES AND TEMP FILESIF EXIST %TEMP%\CURRDATE.TMP Del %TEMP%\CURRDATE.TMPIF EXIST %TEMP%\CURRTIME.TMP Del %TEMP%\CURRTIME.TMPSET CURRDATE=SET CURRTIME=SET YYYY=SET PARSEARG=SET MM=SET DD=SET HHMM=SET NOW=REMTITLE Command PromptUS notation:@Echo OFFTITLE mdUS - Make directory with current date/time (US notation)REM mdUS.CMDREM Make directory with current date/time in a given pathREMREM -------------------------------------------------------------IF %1.==. GoTo USAGESet CURRDATE=%TEMP%\CURRDATE.TMPSet CURRTIME=%TEMP%\CURRTIME.TMPDATE /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%%kSet NOW=%YYYY%_%MM%_%DD%_%HHMM%Echo Make directory %1\%NOW% ?Echo (Press Ctr+C to abort)PauseIF EXIST %1\%NOW% GOTO ERRORIF NOT EXIST %1\%NOW% MD %1\%NOW%CLS IF EXIST %1\%NOW% ECHO Directory %1\%NOW% created successfully!GoTo END:USAGEEcho ...no path specified... aborted!Echo ********************************Echo Usage: mdUS [PATH]Echo ********************************Echo Example: mdUS C: or mdUS C:\TEMPEcho ********************************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 = TimePauseGoTo END:ERRORECHO Directory %1\%NOW% already exists!ECHO Execution aborted...try again in a minute!:ENDREM CLEARING USED VARIABLES AND TEMP FILESIF EXIST %TEMP%\CURRDATE.TMP Del %TEMP%\CURRDATE.TMPIF EXIST %TEMP%\CURRTIME.TMP Del %TEMP%\CURRTIME.TMPSET CURRDATE=SET CURRTIME=SET YYYY=SET PARSEARG=SET MM=SET DD=SET HHMM=SET NOW=REMTITLE Command Promptjaclaz
DotBet Posted February 8, 2005 Posted February 8, 2005 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
gunsmokingman Posted March 2, 2005 Posted March 2, 2005 Here This Makes A Folder Based On date In This Format03-01-2005@echo offcls color F2mode con: Cols=55 Lines=3Title What Year Is It Test 2NLSFUNCSET 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:W1mkdir %D3%-%D2%-%D1%echo.echo Folder %D3%-%D2%-%D1% Was Made!ping -n 3 127.0.0.1>nulexit:e1echo.echo Folder Was Already Made!ping -n 3 127.0.0.1>nul
sixpack Posted March 2, 2005 Posted March 2, 2005 from eu to us, 03-01-2005 to 2005-03-01based on gunsmokingman scriptSET D1=%date:~-4,10%SET D2=%date:~3,-8%SET D3=%date:~-7,-5%echo %D1%-%D3%-%D2%
Nickyt Posted June 27, 2005 Posted June 27, 2005 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!
jaclaz Posted June 27, 2005 Posted June 27, 2005 Looky here:http://www.msfn.org/board/index.php?showtopic=47812jaclaz
Yzöwl Posted July 6, 2005 Posted July 6, 2005 (edited) If you are in the UK with its default date and time format, you could use this one linerif 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 insteadif 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 July 6, 2005 by Yzöwl
gunsmokingman Posted July 9, 2005 Posted July 9, 2005 (edited) This Is A Way To Do It In VBSThey all check for a folder Named By the date If The folder is not there then it makes the folder named after dateIf 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 If2 Lines Using A ArrayThe 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 If3 LinesThe 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 If3 Lines Using A ArrayThe 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 If4 LinesThe 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 IfHere 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.exeecho 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.exeecho 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>nulThis One The Same As The Above But Now Names The Second Folder UserName And Time this one now deletes the vbs file it makes nowThis Line Of Code is approx 665 long in notepad.exeecho 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 July 11, 2005 by gunsmokingman
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now