Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

using the current time to create directory...

Posted on 2001-06-24
3
Medium Priority
?
171 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
The article covers five tools all IT professionals should know about, as they up productivity by a great deal!
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

971 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