create folder with specific name

  • Thread starter Thread starter Gerry Rigney
  • Start date Start date
G

Gerry Rigney

Hi all

I run a series of checks over lunchtime which result in
about 20 txt log files being created. At the end of the
script I'd like to create a folder and move all the files
into it. The folder name has to be in this format though
for post processing.

if it's the 20 of January 2004 the folder must be:

20_01_04

Can anyone help me with a script to create a folder with
such a name ?

I'd appreciate any help on the topic.
Best regards
Gerry
 
Hi all

I run a series of checks over lunchtime which result in
about 20 txt log files being created. At the end of the
script I'd like to create a folder and move all the files
into it. The folder name has to be in this format though
for post processing.

if it's the 20 of January 2004 the folder must be:

20_01_04

Can anyone help me with a script to create a folder with
such a name ?

I'd appreciate any help on the topic.
Best regards
Gerry


Use the script at tip 4835 in the 'Tips & Tricks' at http://www.jsiinc.com
to parse the date into its month, day and year components.

call univdate
cd C:\
md %dd%_%mm%_%yy%


If yy returns 2004, then

call univdate
cd C:\
set yy=%yy:~2,2%
md %dd%_%mm%_%yy%


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
Hi Jerold

That's exactly what I'm looking for, it's not the first
time you've helped me either and your help is greatly
appreciated.

Best regards
Gerry R
 
To create these folders without using an external program,
copy and paste the following 13 Lines:

:::::::::::::::::::::::::::

@ECHO OFF
SETLOCAL
FOR /F "TOKENS=1-4 DELIMS=/ " %%A IN ('DATE/T') DO SET MM=%%B
FOR /F "TOKENS=1-4 DELIMS=/ " %%A IN ('DATE/T') DO SET DD=%%C
FOR /F "TOKENS=1-4 DELIMS=/ " %%A IN ('DATE/T') DO SET YYYY=%%D
IF %YYYY% == 2004 SET YY=04
IF %YYYY% == 2005 SET YY=05
IF %YYYY% == 2006 SET YY=06
IF %YYYY% == 2007 SET YY=07
IF %YYYY% == 2008 SET YY=08
IF %YYYY% == 2009 SET YY=09
MD C:\%DD%_%MM%_%YY%
ENDLOCAL

:::::::::::::::::::::::::::

To extend its functionality beyond the year 2009,
add more "IF" statements after Line 11:
IF %YYYY% == 2010 SET YY=10
IF %YYYY% == 2011 SET YY=11

Line 12 creates a folder under drive C with the current day_month_year
C:\13_01_04
Change the path if necessary:
MD C:\foldername\%DD%_%MM%_%YY%

Add your "MOVE" command(s) after Line 12, before Line 13:
MD C:\%DD%_%MM%_%YY%
MOVE C:\foldername\*.log C:\%DD%_%MM%_%YY%
ENDLOCAL

SETLOCAL (Line 2) & ENDLOCAL (Line 13) protect the code against
the possibility that you have existing variables on your PC named:
DD, MM, YY, or YYYY

I am assuming that you are running Windows 2000,
since the message was posted in a win2000 newsgroup.
This code also works in Windows Server 2003 & Windows XP.
(Tested in 2000/2003/XP on 01/13/2004)


Austin M. Horst
 
Austin said:
To create these folders without using an external program,
copy and paste the following 13 Lines:

:::::::::::::::::::::::::::

@ECHO OFF
SETLOCAL
FOR /F "TOKENS=1-4 DELIMS=/ " %%A IN ('DATE/T') DO SET MM=%%B
FOR /F "TOKENS=1-4 DELIMS=/ " %%A IN ('DATE/T') DO SET DD=%%C
FOR /F "TOKENS=1-4 DELIMS=/ " %%A IN ('DATE/T') DO SET YYYY=%%D
IF %YYYY% == 2004 SET YY=04
IF %YYYY% == 2005 SET YY=05
IF %YYYY% == 2006 SET YY=06
IF %YYYY% == 2007 SET YY=07
IF %YYYY% == 2008 SET YY=08
IF %YYYY% == 2009 SET YY=09
MD C:\%DD%_%MM%_%YY%
ENDLOCAL

:::::::::::::::::::::::::::

To extend its functionality beyond the year 2009,
add more "IF" statements after Line 11:
IF %YYYY% == 2010 SET YY=10
IF %YYYY% == 2011 SET YY=11

Line 12 creates a folder under drive C with the current day_month_year
C:\13_01_04
Change the path if necessary:
MD C:\foldername\%DD%_%MM%_%YY%

Add your "MOVE" command(s) after Line 12, before Line 13:
MD C:\%DD%_%MM%_%YY%
MOVE C:\foldername\*.log C:\%DD%_%MM%_%YY%
ENDLOCAL

SETLOCAL (Line 2) & ENDLOCAL (Line 13) protect the code against
the possibility that you have existing variables on your PC named:
DD, MM, YY, or YYYY

I am assuming that you are running Windows 2000,
since the message was posted in a win2000 newsgroup.
This code also works in Windows Server 2003 & Windows XP.
(Tested in 2000/2003/XP on 01/13/2004)


Austin M. Horst

The following will work for any year without the repetitive IF
statements:

=====begin c:\cmd\demo\DirNamedDate.cmd ====================
1. @ECHO OFF
2. SETLOCAL
3. FOR /F "TOKENS=2-4 DELIMS=/ " %%A IN ('DATE/T') DO (
4. SET MM=%%A&SET DD=%%B&SET YYYY=%%C
5. )
6. SET YY=%YYYY:~2%
7. ECHO MD C:\%DD%_%MM%_%YY%
=====end c:\cmd\demo\DirNamedDate.cmd ====================

Once you create a whole bunch of such directories, you will
find them easier to manage if you change the order of the
date elements in the directory names to YYYY-MM-DD (put the
year first and use all four digits).
 
Back
Top