User Tools

Site Tools


script:powershell:multimedia:photo

This is an old revision of the document!


PowerShell et la photo

Déplacer les fichiers par date vers un autre dossier

$Destination = 'F:\Photos\'
$Source = 'F:\Photos\2019'
Get-ChildItem -Path $Source -File -Filter *.jpg -Recurse| ForEach-Object {
$Year = $_.lastwritetime.year.ToString("0000")
$Month = $_.lastwritetime.month.ToString("00")
$Day = $_.lastwritetime.day.ToString("00")
$D = Join-Path $Destination -ChildPath "$Year\$Month-$Year\$Day-$Month-$Year"
if ((Test-Path $D) -eq $false){New-Item -Path $D -ItemType Directory -Force | Out-Null}
Move-Item -Path $_.FullName -Destination (Join-Path -Path $D -ChildPath $_.name ) -Force
}
Effacer les dossiers vides
# Set to true to test the script
$whatIf = $false
# Remove hidden files, like thumbs.db
$removeHiddenFiles = $false
# Get hidden files or not. Depending on removeHiddenFiles setting
$getHiddelFiles = !$removeHiddenFiles
# Remove empty directories locally
Function Delete-EmptyFolder($path)
{
    # Go through each subfolder, 
    Foreach ($subFolder in Get-ChildItem -Force -Literal $path -Directory) 
    {
        # Call the function recursively
        Delete-EmptyFolder -path $subFolder.FullName
    }
    # Get all child items
    $subItems = Get-ChildItem -Force:$getHiddelFiles -LiteralPath $path
    # If there are no items, then we can delete the folder
    # Exluce folder: If (($subItems -eq $null) -and (-Not($path.contains("DfsrPrivate")))) 
    If ($subItems -eq $null) 
    {
        Write-Host "Removing empty folder '${path}'"
        Remove-Item -Force -Recurse:$removeHiddenFiles -LiteralPath $Path -WhatIf:$whatIf
    }
}
# Run the script
Delete-EmptyFolder -path "E:\_Backup"

script/powershell/multimedia/photo.1604835432.txt.gz · Last modified: 2020/11/08 12:37 by admin