ProgrammingPowerShell

Powershell – Create Year/Month folder structure

Creates multiple folders in specified location for a list of specified years and inserts sub-folders for each month in each year folder.
Scenario: Maintaining dated documents such as photos or receipts. This script quickly creates a suitable folder structure for the years required.

# Inserts 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 'D:\Location\To\Insert\Directories'

$RootLocation = $PWD


$StartYear = 1999
$EndYear = 2024                                                                                                                                          

foreach($Year in @($StartYear..$EndYear))
{
    mkdir $Year
    set-location $PWD/$Year
    foreach($Month in @('01 - Jan', '02 - Feb', '03 - Mar', '04 - Apr', '05 - May', '06 - Jun', '07 - Jul', '08 - Aug', '09 - Sep', '10 - Oct', '11 - Nov', '12 - Dec'))
    {
        mkdir $Month
    }
    set-location $RootLocation
}

One thought on “Powershell – Create Year/Month folder structure

  • Jrdavy

    Works very well. Thanks for this 🙂

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *