Browse Source

Script now correctly reads video files creation date

master
Figg 4 months 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,18 +15,34 @@
15 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 35
 function Get-APFileDateTaken {
19 36
     param (
20 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 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 47
     $culture = Get-Culture
32 48
     $DateTaken = try { [DateTime]::Parse($DateTaken, $culture) } catch { $null }
@@ -58,6 +74,11 @@ function Get-APCreationDateSubDirectory {
58 74
     }
59 75
 }
60 76
 
77
+
78
+###########################################
79
+####              MAIN                #####
80
+###########################################
81
+
61 82
 if (-not $args[0] -or -not $args[1]) {
62 83
     $SourceDir = Read-Host "Veuillez entrer le chemin du dossier source (ou une archive .zip)"
63 84
     $DestinationDir = Read-Host "Veuillez entrer le chemin du dossier destination"

Loading…
Cancel
Save