Solved

using the current time to create directory...

Posted on 2001-06-24
3
159 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A few months ago I had an issue with LaserJet 1020 printer which was installed to XP and Windows 7.  It was installed to XP and working, but when I tried to connect from a Windows 7 PC, it would attempt connection and then fail.  Sometimes the Spool…
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

864 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now