创建名称和日期 +7 天的文件夹结构
create a folder structure with name and date +7 days
我想创建一个以 W1 09-09-2021 开头的文件夹名称(这是文件夹的名称)
我希望第二个是 W2 + 7 天,有没有办法批量创建?比方说 6 个月?
问候
你可以使用类似这样的东西。可能会压缩得更多,但由于您是初学者,我相信如果我这样保留它会学到更多。
记得使用应创建新文件夹的目标完整路径更新 $folderPath
变量。
$startDate = [datetime]'09-09-2021'
$endDate = $startDate.AddMonths(6)
$startWeek = 1
$folderPath = "X:\fullPath\to\newFolders"
$datesToExclude = @(
'12-30-2021' # This will Exclude 30 of December 2021
) | ForEach-Object {$_ -as [datetime]}
do
{
if($startDate -notin $datesToExclude)
{
$folderName = "W{0} {1}" -f $startWeek, $startDate.ToString('MM-dd-yyyy')
$newFolderPath = Join-Path $folderPath -ChildPath $folderName
New-Item $newFolderPath -ItemType Directory
}
$startDate = $startDate.AddDays(7)
$startWeek++
}until($startDate -ge $endDate)
新文件夹从 W1 到 W26:
应该是这样的
W1 09-09-2021
W2 09-16-2021
W3 09-23-2021
W4 09-30-2021
...
...
...
W24 02-17-2022
W25 02-24-2022
W26 03-03-2022
我想创建一个以 W1 09-09-2021 开头的文件夹名称(这是文件夹的名称) 我希望第二个是 W2 + 7 天,有没有办法批量创建?比方说 6 个月? 问候
你可以使用类似这样的东西。可能会压缩得更多,但由于您是初学者,我相信如果我这样保留它会学到更多。
记得使用应创建新文件夹的目标完整路径更新 $folderPath
变量。
$startDate = [datetime]'09-09-2021'
$endDate = $startDate.AddMonths(6)
$startWeek = 1
$folderPath = "X:\fullPath\to\newFolders"
$datesToExclude = @(
'12-30-2021' # This will Exclude 30 of December 2021
) | ForEach-Object {$_ -as [datetime]}
do
{
if($startDate -notin $datesToExclude)
{
$folderName = "W{0} {1}" -f $startWeek, $startDate.ToString('MM-dd-yyyy')
$newFolderPath = Join-Path $folderPath -ChildPath $folderName
New-Item $newFolderPath -ItemType Directory
}
$startDate = $startDate.AddDays(7)
$startWeek++
}until($startDate -ge $endDate)
新文件夹从 W1 到 W26:
应该是这样的W1 09-09-2021
W2 09-16-2021
W3 09-23-2021
W4 09-30-2021
...
...
...
W24 02-17-2022
W25 02-24-2022
W26 03-03-2022