Solved

using the current time to create directory...

Posted on 2001-06-24
3
160 Views
Last Modified: 2013-12-28
I need to give some of my users a unique directory name each time they logon (the reasons why i won't go in to!) and the best way to do this that i an think of is using parsing the system 'time' into the directory....in conjunction with their clientname...

ie.  CLIENTNAME_SYStime

problem is how do i get the system to create this directory using the time, with out the colons and other info tht comes when entering 'time' or 'time /t', also i need this in reverse order with seconds (2 d.p)

ie. if its 23:03:33, i need   CLIENTNAME_330323

thanks,

Ian.
0
Comment
Question by:impoole
3 Comments
 
LVL 1

Expert Comment

by:TommyLister
ID: 6224805
Try this

@ECHO OFF

for /F "tokens=1-2 delims=: " %%i in ('time /t') do (
   set hours=%%i
   set Mins=%%j
   set time=%%i_%%j
)

ECHO time is %time%

Tommy.
0
 
LVL 3

Accepted Solution

by:
czpczp earned 100 total points
ID: 6225097
Hi impoole.  The following script does *exactly* what you're looking for.  It will use the Time command (not time/t 'cause it doesn't give the seconds which is what you want), and parses the output string to extract the time in reverse order SEC:MIN:HR *extracting* the semi-colons.  THEN, it creates a directory *including* the client's name.  I did extensively test the script using varying times without having any problems.


Cut and paste (verbatim) the script below into file with a BAT extension.  The following creates the directory on the root of the current drive (last line) -- you can alter where the directory is created depending on your needs (i.e. Md F:\LOG\%UserName%_%DirTemp%).



Rem  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  MakeDir.Bat ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@echo off
cls

REM ** the following line gets the current time into a variable
echo.|time >holdstr

REM ** The following 5 For statements parse the holdstr var to extract the time in reverser order
for /f "eol=E tokens=1,2,3*" %%a IN (holdstr) do echo %%a%%b%%c%%d  >holdstr
for /f "tokens=1,2* delims= " %%a IN (holdstr) do echo %%b  >holdstr
for /f "tokens=1,2* delims=." %%a IN (holdstr) do echo %%a  >holdstr
for /f "tokens=1,2,3 delims=:" %%a IN (holdstr) do echo %%c%%b%%a  >holdstr
for /f "tokens=1,2* delims= " %%a IN (holdstr) do set DirTemp=%%a%%b

REM ** remove temp file
del holdstr

Md \%UserName%_%DirTemp%

Rem  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  MakeDir.Bat ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



If you have any questions, please let me know.
Regards, Steve
0
 

Author Comment

by:impoole
ID: 6225330
great stuff, worked first time...

thanks......
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question