Solved

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

Posted on 2004-03-31
12
8,595 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
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

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

12 Experts available now in Live!

Get 1:1 Help Now