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"

Lire des informations dans un fichier image

Function Get-Image
{
    begin{        
         [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") |Out-Null 
    } 
     process{
          $fi=[System.IO.FileInfo]$_           
          if( $fi.Exists){
               $img = [System.Drawing.Image]::FromFile($_)
               $img.Clone()
               $img.Dispose()       
          }else{
               Write-Host "File not found: $_" -fore yellow       
          }   
     }    
    end{}
}

Get-ChildItem -Path "F:\Deploy\Scripts\Misc\SG - SetWallpaper\Source\Wallpaper" -Filter *.jpg | ForEach-Object {
    $image = $_ | Get-Image
    New-Object PSObject -Property  @{ 
        File = $_.name
        Fullname = $_.Fullname
        Height = $image.Height
        Width = $image.Width
    };
}

script/powershell/multimedia/photo.1622562147.txt.gz · Last modified: 2021/06/01 17:42 by admin