?
Solved

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

Posted on 2004-03-31
12
Medium Priority
?
8,752 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

765 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