Solved

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

Posted on 2004-03-31
12
8,635 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DOS command won't run from WScript.Shell 8 57
push same scheduled task across multiple servers? 16 164
Excel: Move files in a folder 8 74
Printing Folders, SubFolders, Files. 16 204
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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