-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRename Selected Media Files.fh_lua
37 lines (37 loc) · 1.25 KB
/
Rename Selected Media Files.fh_lua
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
--[[
@Title: Rename Media to Match Title Field
@Author: Jane Taubman
@Version: 1.0
@LastUpdated: March 2011
@Description:
Renames Selected Media Files to the Name in the Title
excluding characters not allowed in file names.
]]
function splitfilename(strfilename)
-- Returns the Path Filename and extension as 3 values
return string.match(strfilename, "(.-)([^\\]-([^%.]+))$")
end
------------------------------------------------------------ Main Code
tblPtrList = fhPromptUserForRecordSel('OBJE')
strMediaDir = fhGetContextInfo('CI_PROJECT_DATA_FOLDER')
ptrFile = fhNewItemPtr()
if #tblPtrList == 0 then
fhMessageBox('User cancelled')
else
for _,ptr in pairs(tblPtrList) do
ptrFile:MoveTo(ptr,'~._FILE')
id = fhGetRecordId(ptr)
path,file,ext = splitfilename(fhGetItemText(ptrFile,'~'))
newfile = 'O'..id..'_'..string.gsub(fhGetItemText(ptr,'~.TITL'),'[_%W]','_')..'.'..ext
print(fhGetDisplayText(ptr),id, path, file, newfile)
if string.sub(path,1,5) == 'Media' then
-- File in Media Folder so extend path
path2 = strMediaDir..'\\'..path
else
path2 = path
end
print(fhGetDisplayText(ptr),id, path2, file, newfile, string.sub(path,1,5))
fhSetValueAsText(ptrFile,path..newfile)
os.rename(path2..file,path2..newfile)
end
end