Solved

using the current time to create directory...

Posted on 2001-06-24
3
158 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
Comment Utility
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
Comment Utility
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
Comment Utility
great stuff, worked first time...

thanks......
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Windows Mobile Barcode Scanning These days almost every product has a barcode in some way... amongst there are 1D barcodes en 2D barcodes.. From http://www.barcodeman.com/faq/2d.php I found some handy definitions and insights. 1D barcodes …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

771 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

10 Experts available now in Live!

Get 1:1 Help Now