Solved

Batch file to create Folder & files with Weekdays Name eg: MON,TUE etc.)

Posted on 2004-03-31
12
8,609 Views
Last Modified: 2010-12-01
i need to create a batch file that will automatically create folders or files with the names of current Month (JAN, FEB, MAR) and Weekdays (MON,TUE,WED) by automatically cheking current system date. say if today is '31 Wednesday, March 2004' it should create a folder "c:\DATA\MAR\WED" or "c:\Data\MAR\FRI.txt" and so on. so please tell me how to create that. or give the example.

iam interested in automatic backup of my data files through using batch files by windows tasksheduler.

Any one has the answer?... please i need it..
0
Comment
Question by:moin_deen
12 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 10724303
Try this:

@echo off

setlocal

for /F "tokens=1,2 delims=/ " %%a in ('date /t') do (
 set day=%%a
 set mm=%%b
)

set /A mm=1%mm% - 100 + 0

if %mm%==1 set month=Jan
if %mm%==2 set month=Feb
if %mm%==3 set month=Mar
if %mm%==4 set month=Apr
if %mm%==5 set month=May
if %mm%==6 set month=Jun
if %mm%==7 set month=Jul
if %mm%==8 set month=Aug
if %mm%==9 set month=Sep
if %mm%==10 set month=Oct
if %mm%==11 set month=Nov
if %mm%==12 set month=Dec

if not exist c:\data\%month%\%day:~0,3%\nul mkdir c:\data\%month%\%day:~0,3%

Good Luck,
Steve
0
 
LVL 1

Expert Comment

by:pauldoherty
ID: 10816713
Try my utility DateSet - you simply invoke it at the top of your BAT file and after that line you will have easy access to these variables within your BAT file:

DATE (example value - 10242002)
DAY (example value - 24)
DAYWORD (example value - Thu)
MONTH (example value - 10)
SHORTYEAR (example value - 02)
YEAR (example value - 2002)
HOURS (example value - 11)
MINS (example value - 03)
SECS (example value - 39)
AMPM (example value - AM)

DateSet is available here - click "Downloads" at the left.

http://powerusers.info
0
 
LVL 1

Expert Comment

by:ico2
ID: 10969192
once you have done that (assuming the data is set to the envioroment variables year month day use this code.

mkdir %year%
cd %year%
mkdir %month%
cd %month%
mkdir %day%
cd %day%

when run on the next day it will produce a couple of messages (directory already exists) but will run just fine.
0
 

Author Comment

by:moin_deen
ID: 10984848
Hi.

Thank you for your prompt response.

I have tried all the batch Codes that were posted to my question. i could not get the result, Syntex error appear when ever i tried to execute the batch file. i don't have much programming techiniques, also iam new to batch file programming,

Please Give me a working EXAMPLE of batch file.

Thank You
regards
Moindeen
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 10985773
What's your operating system version?
0
 

Author Comment

by:moin_deen
ID: 10988861
Hi Steve

The operating system currently installed in my system is.

Windows 98 Second Edition [Version 4.10.2222]

regards
Moindeen
0
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.

 
LVL 30

Expert Comment

by:SteveGTR
ID: 10988962
When you type date and the command line how does the current date display. Include the weekday if present.
0
 

Author Comment

by:moin_deen
ID: 10989052
if i type DATE at the command propmt this is the result.

C:\>date
Current date is Wed 05-05-2004

0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 10989079
I'm sorry, but I can't tell the format with todays date. What does the format say in the next line of the date command? Something like Enter the new date: (mm-dd-yy).
0
 

Author Comment

by:moin_deen
ID: 10989100
C:\>date
Current date is Wed 05-05-2004
Enter new date (mm-dd-yy):
0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 125 total points
ID: 10989418
Give this a try:

@echo off

echo.|date>_temp.bat

find "The current date" _temp.bat>NUL
if ERRORLEVEL 1 goto OldVer

echo @set day=%%4>the.bat
echo @set curdate=%%5>>the.bat

goto GetDate

:OldVer

echo @set day=%%3>current.bat
echo @set curdate=%%4>>current.bat

:GetDate

call _temp.bat

echo @set month=>temp1.txt
echo e 10b 1a>temp.txt
echo e cx>>temp.txt
echo c>>temp.txt
echo w>>temp.txt
echo q>>temp.txt
type temp.txt | debug temp1.txt > NUL
echo %curdate%>temp2.txt
echo e 102 0d 0a 1a>temp.txt
echo e cx>>temp.txt
echo 5 >>temp.txt
echo w>>temp.txt
echo q>>temp.txt
type temp.txt | debug temp2.txt > NUL
copy temp1.txt+temp2.txt _temp.bat > NUL

call _temp.bat > NUL

if "%month%"=="01" set month=Jan
if "%month%"=="02" set month=Feb
if "%month%"=="03" set month=Mar
if "%month%"=="04" set month=Apr
if "%month%"=="05" set month=May
if "%month%"=="06" set month=Jun
if "%month%"=="07" set month=Jul
if "%month%"=="08" set month=Aug
if "%month%"=="09" set month=Sep
if "%month%"=="10" set month=Oct
if "%month%"=="11" set month=Nov
if "%month%"=="12" set month=Dec

REM ** Remove the echo from the beginning of this line to actually create the directory
echo if not exist c:\data\%month%\%day%\nul mkdir c:\data\%month%\%day%

set month=
set day=
set curdate=

del _temp.bat>NUL
del temp1.txt>NUL
del temp2.txt>NUL
del temp.txt>NUL
if exist the.bat del the.bat>NUL
if exist current.bat del current.bat>NUL

Note, you have to remove the echo from below the REM line to actually create the directory.
0
 

Author Comment

by:moin_deen
ID: 10992739
Hi  Steave,

Your code indeed worked great. I really Thank you for posting a best solution  to my question.

regards
Moindeen
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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

15 Experts available now in Live!

Get 1:1 Help Now