Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-03-31
12
Medium Priority
?
8,789 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 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