-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRename_ImageFile.ps1
More file actions
38 lines (25 loc) · 1.11 KB
/
Rename_ImageFile.ps1
File metadata and controls
38 lines (25 loc) · 1.11 KB
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
param ([string]$imageFilePath, [string]$uploadSheetFile)
<#
Purpose: the script will rename the filename of the image to be "PubNum.jpg"
- the file need to have a column call "pubnum"
Create Date: 6/19/2017
Created By: Tommy Yuen
Command: powershell -f rename_imagefile.ps1 -imageFilePath c:\imagelocation -uploadSheetFile c:\temp\pubnumlist.csv
#>
# list of pubnum from upload sheet
$fileDataList = import-csv $uploadSheetFile
# loop through the network path
get-childitem $imageFilePath | ForEach-Object {
$fileName = $_.FullName
# for each file in the network path, check to see if it matches the pub num
foreach ($itemrow in $fileDataList) {
# if the pubnum matches, then it will rename it to pubnum.jpg
if ($fileName -match $file.PubNum ) {
$newFileName = $itemrow.PubNum + '.jpg'
write-host "pubnum: " $itemrow.PubNum
write-host 'current: ' $fileName
write-host 'new: ' "$imageFilePath\$newFileName"
Rename-Item $fileName "$imageFilePath\$newFileName"
}
}
}