PoshCode Archive  Artifact [dbee94dc31]

Artifact dbee94dc31e3699e4fda0c6a7e8c5c726d21ee79c05629337bcb87447f67a34b:

  • File Dir-for-days.ps1 — part of check-in [d0f9097407] at 2018-06-10 13:32:14 on branch trunk — Correction of : Creates directories for every day within a given time period. (user: dirdays size: 1165)

# encoding: ascii
# api: powershell
# title: Dir for days
# description: Correction of : Creates directories for every day within a given time period. 
# version: 0.1
# type: function
# author: dirdays
# license: CC0
# function: Create-DatePaths
# x-poshcode-id: 3856
# x-archived: 2013-01-09T07:24:50
# x-published: 2013-01-02T02:00:00
#
# The previous script failed on my system because it has a different locale. For example: ‘Oct’ would be ‘Okt’. This function eliminates that problem.
# typo fix: line 12 $Destination should be $DestinationPath
#
Function Create-DatePaths {
    Param (
        [Parameter(Position=0,Mandatory=$True)]
        [DateTime] $Start,
        [Parameter(Position=1,Mandatory=$True)]
        [ValidateScript({$_ -gt $Start})]
        [DateTime] $End,
        $DestinationPath=(Join-Path $env:UserProfile "Test")
    )

    0..(New-TimeSpan $Start $End).Days | % {
        $TargetPath = Join-Path $DestinationPath $(Get-Date $Start -Format "yyyy\\MM-MMMM\\yyyy-MM-dd")
        If (!(Test-Path $TargetPath)) { New-Item $TargetPath -ItemType Directory }
        $Start = $Start.AddDays(1)
    }
}