Browse Source

Script now correctly reads video files creation date

master
Figg 1 month ago
parent
commit
84441f7b9f
1 changed files with 27 additions and 6 deletions
  1. 27
    6
      ArrangePictures.ps1

+ 27
- 6
ArrangePictures.ps1 View File

15
     return $extensions
15
     return $extensions
16
 }
16
 }
17
 
17
 
18
+function Get-FileMetaData {
19
+    param (
20
+        [string] $filePath,
21
+        [int] $propertyIndex
22
+    )
23
+
24
+    $folder = (New-Object -ComObject Shell.Application).NameSpace((Split-Path -Parent $filePath))
25
+    $folderItem = $folder.ParseName((Split-Path -Leaf $filePath))
26
+
27
+    $property = $Folder.GetDetailsOf(
28
+        $folderItem,
29
+        $propertyIndex
30
+    )
31
+
32
+    return $property
33
+}
34
+
18
 function Get-APFileDateTaken {
35
 function Get-APFileDateTaken {
19
     param (
36
     param (
20
         [string] $FilePath
37
         [string] $FilePath
21
     )
38
     )
22
-    $Folder = (New-Object -ComObject Shell.Application).NameSpace((Split-Path $FilePath))
23
-    $PropIndex = 12  # Date Taken Property Index
39
+    #$PropIndex = 208  # Image Date Taken Property Index ; 208 = vidéo ; 11 = File type
24
     $CharWhiteList = '[^: \w\/]'
40
     $CharWhiteList = '[^: \w\/]'
41
+    $type = (Get-FileMetaData -FilePath $FilePath -PropertyIndex 11)
42
+    if ($type -ieq "vidéo") { $PropIndex = 208 }
43
+    if ($type -ieq "image") { $PropIndex = 12 }
25
 
44
 
26
-    $DateTaken = $Folder.GetDetailsOf(
27
-        $Folder.ParseName((Split-Path -Leaf $FilePath)),
28
-        $PropIndex
29
-    ) -replace $CharWhiteList
45
+    $DateTaken = (Get-FileMetaData -FilePath $FilePath -PropertyIndex $PropIndex) -replace $CharWhiteList
30
 
46
 
31
     $culture = Get-Culture
47
     $culture = Get-Culture
32
     $DateTaken = try { [DateTime]::Parse($DateTaken, $culture) } catch { $null }
48
     $DateTaken = try { [DateTime]::Parse($DateTaken, $culture) } catch { $null }
58
     }
74
     }
59
 }
75
 }
60
 
76
 
77
+
78
+###########################################
79
+####              MAIN                #####
80
+###########################################
81
+
61
 if (-not $args[0] -or -not $args[1]) {
82
 if (-not $args[0] -or -not $args[1]) {
62
     $SourceDir = Read-Host "Veuillez entrer le chemin du dossier source (ou une archive .zip)"
83
     $SourceDir = Read-Host "Veuillez entrer le chemin du dossier source (ou une archive .zip)"
63
     $DestinationDir = Read-Host "Veuillez entrer le chemin du dossier destination"
84
     $DestinationDir = Read-Host "Veuillez entrer le chemin du dossier destination"

Loading…
Cancel
Save