How do I add the current weeknumber to my foldername
Posted: 29 Apr 2016 07:29
Hi, since I am relatively new to batch files and this forum, I will explain what I am trying to do.
I am trying to create a bat script that will create a new folder starting with the current date, some text, followed by the current week number.
I am using the script below to make the new directory with the current date and some text:
This part is working fine. But instead of "20160429 Foldername" I would like to have "20160429 Foldername 17". Where 17 is the current week based on the current date.
I did find the script below which seems to give me the correct week. But how do I incorporate this in the script above so the foldername includes the 17? Or is there an easier way to do this?
I would appreciate any help.
Kind regards, dieger
I am trying to create a bat script that will create a new folder starting with the current date, some text, followed by the current week number.
I am using the script below to make the new directory with the current date and some text:
Code: Select all
@echo off
echo Get the current date and time in YYYYMMDD format
cls
echo.
SET isodt=%date:~9,4%%date:~6,2%%date:~3,2%
set date=%isodt%
echo.
mkdir "%isodt% Foldername"
This part is working fine. But instead of "20160429 Foldername" I would like to have "20160429 Foldername 17". Where 17 is the current week based on the current date.
I did find the script below which seems to give me the correct week. But how do I incorporate this in the script above so the foldername includes the 17? Or is there an easier way to do this?
Code: Select all
REM @echo off
REM Set needed options
setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION
REM Extract date components from current date
set /a MM=%DATE:~6,2%
set /a DD=%DATE:~3,2%
set /a YYYY=%DATE:~9,4%
set YY=%DATE:~11,4%
REM Get Weeknumber
call :WeekNumber %MM% %DD% %YYYY%
echo %Week%
pause
goto :Exit
:WeekNumber
REM Calculate an offset based on day of week January 1 fell on
set /a Offset=%3-1900
set /a Offset=((%Offset%+(%Offset%/4))%% 7)+6
REM Find out what day of the year (from January 1) we are on
call :DayNumber %1 %2 %3
REM Add offset and then divide by 7 days per week
set /a Week=(%Day%+%Offset%)/7 -1
goto :Exit
:DayNumber
REM Incrementally build up dy number from month and day
set /a Day=0
goto :DayNumber%1
:DayNumber12
set /a Day+=30
:DayNumber11
set /a Day+=31
:DayNumber10
set /a Day+=30
:DayNumber9
set /a Day+=31
:DayNumber8
set /a Day+=31
:DayNumber7
set /a Day+=30
:DayNumber6
set /a Day+=31
:DayNumber5
set /a Day+=30
:DayNumber4
set /a Day+=31
:DayNumber3
set /a Day+=28
REM Add an extra day on leap years
set /a Leap=%3 %%4
if %Leap% == 0 set /a Day+=1
:DayNumber2
set /a Day+=31
:DayNumber1
set /a Day+=%2
goto :Exit
:Exit
I would appreciate any help.
Kind regards, dieger