-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSort-Images.ps1
44 lines (30 loc) · 1.06 KB
/
Sort-Images.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Basic Powershell script to sort images
# Objects we manually change go in the beginning
$drive = “C:\”
# simple array of filetypes
$FileTypes = (‘*.png’,’*.bmp’,’*.jpg’,’*.jpeg’)
# Move to drive with pictures
Set-Location -Path $drive
# Gather all the pictures into object array
$objArray = @()
Foreach ($type in $FileTypes){
$objArray += Get-ChildItem -Recurse -Filter $type
}
# Collect objects name and size into hashtable
$hashtable = @{}
Foreach ($object in $objArray)
{
$name = $object.FullName
$length = $object.Length
$hashtable.Add($name,$length)
}
# Displays table of files&sizes
$hashtable.GetEnumerator() | Out-GridView
# Create Folders for pics
If (!('C:\temp')){New-Item -Path "c:\" -Name "temp" -ItemType "directory"}
Set-Location c:\temp
New-Item -Name "png" -ItemType "directory"
New-Item -Name "jpg" -ItemType "directory"
# Sort Pics into Folders
$objArray | %{If ($_.FullName -like ‘*png’){Copy-Item $_.FullName png }}
$objArray | %{If ($_.FullName -like ‘*jpg’){Copy-Item $_.FullName jpg }}