我正在尝试制作一个批处理文件,以创建从 4 月开始到 3 月结束的 12 个文件夹。我不知道如何让输入的日期转到 set year1= 或如何让日期设置为 1 年后 year2。这是我目前所拥有的。
@echo off
Rem( user input required say 2023 )
set /p input= Type The Year :
Rem ( 2023 from user input )
set Year1=
Rem ( 2023 from user input + 1 year )
set Year2=
MKDIR %year%
CD %year%
:: GOTO FULL_MONTH
:FULL_MONTH
mkdir "01 - April %Year1%"
mkdir "02 - May %Year1%"
mkdir "03 - June %Year1%"
mkdir "04 - July %Year1%"
mkdir "05 - August %Year1%"
mkdir "06 - September %Year1%"
mkdir "07 - October %Year1%"
mkdir "08 - November %Year1%"
mkdir "09 - December %Year1%"
mkdir "10 - January %Year2%
mkdir "11 - February %Year2%
mkdir "12 - March %Year2%
:DONE
Dir
Pause
答案1
您可以使用以下 cmdlet 通过 Powershell 执行此操作。
设置开始日期,然后在创建文件夹时使用计数器循环遍历月份。
###Get the year entered by the user
$year = Read-Host "Please enter year"
###Set the starting date
$startdate = [DateTime] "01 April $($year)"
$count = 1
###Create folder based on the year entered by the user
New-Item -ItemType Directory -Name "$($year)"
###Change directory to the newly created folder
cd "$($year)"
While ( $count -lt 13)
{
###Create folders
New-Item -ItemType Directory -Name "$($count.ToString('00')) - $($startdate.ToString('MMMM yyyy'))"
#Add one month
$startdate = $startdate.AddMonths(1)
#Increment the counter
$count = $count + 1
}