Code
$Shell = New-Object -ComObject shell.application
# Iterate through each folder
Get-ChildItem -Recurse -Directory -ErrorAction Stop | ForEach{
Write-Output "next folder"
$Folder = $Shell.NameSpace($_.FullName)
Write-Output "Folder:"
Write-Output $Folder
$File = Get-ChildItem -Path $_.FullName -Force -filter "*.jpg" -File | Select-Object -First 1
Write-Output "File.Name:"
Write-Output $File.Name
$File2 = $Folder.ParseName($File.Name)
# Write-Output $File2
$Property = $Folder.GetDetailsOf($File2,12)
#$File = $Folder.ParseName($_.Name)
Write-Output "Property:"
Write-Output $Property
#Get date in the required format as a string
$RawDate = ($Property -Replace "[^\w /:]")
Write-Output "RawDate:"
Write-Output $RawDate
$DateTime = [DateTime]::ParseExact($RawDate, "dd/MM/yyyy HH:mm", $null)
Write-Output "DateTime:"
Write-Output $DateTime
$DateTaken = $DateTime.ToString("yyyyMMdd")
Write-Output "DateTaken:"
Write-Output $DateTaken
# Find the available file name
$FolderName = $DateTaken
# Rename file
Write-Output $_.Name"=>"$FolderName #Which folder was renamed into what
Rename-Item -Path $_.FullName -NewName $FolderName
}
# You can run this script using the following command
# .\rename.ps1 -ErrorAction Stop
Alles anzeigen
Hi Ihr, ich habe eine Sony Kamera und die Ordner haben grauenhafte Namen.
Daher hab ich mir ein Windows Script geschrieben, das mir pro Ordner Date Taken ausließt für die erste JPG pro Ordner um nimmt YYYYMMDD als Format.
Die Write Outputs sind Debugausgaben.
Wird in dem Ordner angewendet der die umzubenennenden Ordner enthält.
LG
Seikusa