EDIT: I've missed DDMMYYYY
requirement, fixed now.
Powershell one-liners. Just open the PowerShell console in your directory and run:
Compact:
1..([datetime]::DaysInMonth([datetime]::Now.Year,[datetime]::Now.Month)) | % {md ".\$(([datetime]::ParseExact("$_/$([datetime]::Now.Month)/$([datetime]::Now.Year)", 'd/M/yyyy', [System.Globalization.CultureInfo]::InvariantCulture)).ToString('ddMMyyyy'))"}
No aliases:
1..([datetime]::DaysInMonth([datetime]::Now.Year,[datetime]::Now.Month)) | ForEach-Object {New-Item -ItemType Directory -Path ".\$(([datetime]::ParseExact("$_/$([datetime]::Now.Month)/$([datetime]::Now.Year)", 'd/M/yyyy', [System.Globalization.CultureInfo]::InvariantCulture)).ToString('ddMMyyyy'))"}
Human-readable:
1..([datetime]::DaysInMonth([datetime]::Now.Year,[datetime]::Now.Month)) |
ForEach-Object {
New-Item -ItemType Directory -Path ".\$(([datetime]::ParseExact("$_/$([datetime]::Now.Month)/$([datetime]::Now.Year)", 'd/M/yyyy', [System.Globalization.CultureInfo]::InvariantCulture)).ToString('ddMMyyyy'))"
}
This is more script-like, you'd have to save it as CreateFolders.ps1
and run from PowerShell console like this: .\CreateFolders.ps1
. Commented, so you can actually understand what's happening under the hood:
# Get current Year and Month
$CurrYear = [datetime]::Now.Year
$CurrMonth = [datetime]::Now.Month
# Create new array with numbers from 1 to DaysInMonth
1..([datetime]::DaysInMonth($CurrYear, $CurrMonth)) |
# For each element in array
ForEach-Object {
# Generate name for new directory in ddMMyyyy format
# To do so, we create new DateTime Object with day from pipeline and current year and month
# Then we convert it to the abovementioned format
$DirName = ([datetime]::ParseExact("$_/$CurrMonth/$CurrYear", 'd/M/yyyy', [System.Globalization.CultureInfo]::InvariantCulture)).ToString('ddMMyyyy')
# Correctly join path with current directory and new folder name
$Path = Join-Path -Path (Get-Location).Path -ChildPath $DirName
# Create new directory
New-Item -ItemType Directory -Path $Path
}
Related question: Get the number of Days in the current month using powershell
Unfortunately, we are not a code-writing service. Instead of simply asking for code to perform a particular task, please show us what you've tried so far (including any code you currently have) and where you're stuck so that we can help you with your specific problem. Questions that only ask for code are too broad and are likely to be put on hold or closed.
– bwDraco – 2015-03-20T22:56:18.327