Guest User

Copy Multilevel Folder Name

a guest
Jul 2nd, 2020
28
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function setup(prefs)
  2.  
  3. return function (metadata)
  4. local trimmedPath=strutil.upToLastOccurrenceOf(metadata.Pathname,'/') -- Trims lowest folder level.
  5. local parentFolder=strutil.fromLastOccurrenceOf(metadata.Pathname,'/') -- Gets parent folder's string.
  6. local grandParentFolder=strutil.fromLastOccurrenceOf(trimmedPath,'/') -- Gets grandparent folder's string.
  7. local changedMetadata={}
  8. if prefs.action=='COPY' then
  9. changedMetadata[prefs.destfield1]=parentFolder
  10. changedMetadata[prefs.destfield2]=grandParentFolder
  11. elseif prefs.action=='PREPEND' then
  12. changedMetadata[prefs.destfield1]=parentFolder..(metadata[prefs.destfield1] or '')
  13. changedMetadata[prefs.destfield2]=grandParentFolder..(metadata[prefs.destfield2] or '')
  14. elseif prefs.action=='APPEND' then
  15. changedMetadata[prefs.destfield1]=(metadata[prefs.destfield1] or '')..parentFolder
  16. changedMetadata[prefs.destfield2]=(metadata[prefs.destfield2] or '')..grandParentFolder
  17. end
  18.  
  19. return changedMetadata
  20.  
  21. end
  22. end
  23.  
  24. function buildUI()
  25.  
  26. local builder=smbuilder()
  27. local c=builder:createView('{"text":"COPY MULTILEVEL FOLDER NAME","bounds" : "0,0,parent.width,120"}')
  28. assert(c,"unable to create view object")
  29. -- Parent folder's UI
  30. assert(builder:create('combo',{["id"] = "action", ["options"] = {"COPY","APPEND","PREPEND"}, ["bounds"]="25,42,150,67",["text"]="COPY"}))
  31. assert(builder:create('label','{ "bounds":"155,42,280,67","text":"parent folder to", "align" : "left"}'))
  32. assert(builder:create('combo','{"id" : "destfield1", "options" : "stringFields", "bounds":"285,42,415,67","text":"SubCategory"}'))
  33. -- Grandparent folder's UI
  34. assert(builder:create('combo',{["id"] = "action", ["options"] = {"COPY","APPEND","PREPEND"}, ["bounds"]="25,72,150,97",["text"]="COPY"}))
  35. assert(builder:create('label','{ "bounds":"155,72,330,97","text":"grand parent folder to", "align" : "left"}'))
  36. assert(builder:create('combo','{"id" : "destfield2", "options" : "stringFields", "bounds":"335,72,465,97","text":"Show"}'))
  37. builder:register(c,setup)
  38. -- Now inject this
  39. return c
  40.  
  41. end
  42. --[[ ========================================================== ]]--
  43. return buildUI
RAW Paste Data