我不是程序员,但我尝试修改在这里找到的PS脚本,仍然无法得到我想要的结果。对我来说最难的部分是两位数字日期需求(dd)。经过几次尝试,我想寻求帮助。
我有一个包含数百个JPG文件的文件夹。我根据拍摄日期手动将这些JPG文件排序到不同的文件夹中。文件夹示例名称为2015.02.04、2016.10.31、2016.12.01。
1)我想要一个脚本来扫描我的JPG文件夹。 2)对于每个文件,扫描日期 3)如果文件是在2016年6月1日创建的,则将其移动到.\2016.06.01
能帮个忙吗?
$Filepath = ""
$file = ""
$date = ""
$month = ""
$year = ""
$MonthPath = ""
$FilePath = Read-Host "Place the directory which contains the files."
Write-Warning "Note: This action can take several minutes, depending on the amount of files in $FilePath."
get-childitem $FilePath | % {
$file = $_.FullName
$date = Get-Date ($_.LastWriteTime)
$month = $date.month
$year = $date.year
$day = $date.day
$MonthPath = "$FilePath\$year.$month.$day"
Write-Verbose "month = $month"
Write-Verbose "Date = $date"
Write-Verbose "year = $year"
Write-Verbose "FilePath = $FilePath"
Write-Verbose "Filename = $file"
Write-Verbose "MonthPath = $MonthPath"
if(!(Test-Path -Path "$MonthPath" )){
Write-Verbose "Creating log location $MonthPath."
#Write-Host -backgroundcolor green -ForegroundColor black "Creating log location $MonthPath."
Write-Verbose "MonthPath inside path test = $MonthPath"
New-Item -ItemType directory -Path $MonthPath | Out-null
}
ELSE {
#Write-Host -backgroundcolor green -ForegroundColor black "Log location exists already exist $MonthPath"
Write-Verbose "Log location exists already exist $MonthPath"
}
move-item "$file" "$MonthPath" | Out-null
}
Write-Warning "All files are sorted now based upon year and month."