Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using the current time to create directory...

Posted on 2001-06-24
3
Medium Priority
?
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
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…

670 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