8.20.2023

Powershell Script to create folders with code options

#Creates directories from a specified start year to an end year and 12 months in each year for each month

# Specify where the folders are to be located
Set-Location 'C:\Temp\'

$RootLocation = $PWD


$StartYear = 2023
$EndYear = 2024 
             

foreach($Year in $StartYear..$EndYear)
{
md $Year

    for ($i=01; $i -le 12; $i++)
    {
        if ($i -le 9)
            {
                $foldername = (-join("$Year", "0", $i))
                md ".\$Year\$foldername"
            }
        else 
            {md ".\$Year\$Year$i"}
    }

}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.