Guest User

Change FilePath

a guest
Jul 2nd, 2020
33
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Change FilePath
  2. -- July 16, 2012.
  3. -- Written by Justin Drury
  4. -- specialized version that doesn't change the waveform table...
  5.  
  6. allowUndo=true
  7.  
  8. --[[ ???????
  9. changedMetadata['_ChangeFilePath']=true -- a little flag to tell soundminer to go and build pathname & filepath hash from the filepath
  10. --changedMetadata.['_UpdateWaveforms']=aw:getToggleButtonState() -- another flag to tell SM to also update the waveform table
  11. ]]--
  12. -- This uses a Lua capability called closure.
  13. results=smbigint()
  14.  
  15. function setup()
  16. local validate=userPrefs.validateFilePath
  17. print(type(userPrefs.validateFilePath),userPrefs.validateFilePath,validate)
  18. aw=smalertwindow('FilePath Change','This will change the filepath for the selected records.')
  19. aw:addTextEditor(userPrefs.lastFilePathFind,'Find:','findbox',false)
  20. aw:addTextEditor(userPrefs.lastFilePathReplace,'Replace:','replacebox',false)
  21. aw:addToggleButton("Check that file exists before changing",{250,30},'validate',validate)
  22. aw:addCancelButton()
  23. aw:addOkButton()
  24. if aw:runAlert()==1 then
  25. local findString=aw:getTextEditorContents('findbox')
  26. userPrefs.lastFilePathFind=findString -- save this pref for recall later
  27.  
  28. local replaceString=aw:getTextEditorContents('replacebox')
  29. userPrefs.lastFilePathReplace=replaceString
  30.  
  31. userPrefs.validateFilePath=aw:getToggleButtonState('validate')
  32.  
  33. if findString==string.char() or replaceString==string.char() then
  34. return nil
  35. end
  36. return function(fileMetadata)
  37. local changedMetadata={}
  38. changedMetadata.FilePath=strutil.replace(fileMetadata.FilePath,findString,replaceString)
  39. if userPrefs.validateFilePath then
  40. local fileCheck=smfile(changedMetadata.FilePath)
  41. if not fileCheck:existsAsFile() then
  42. -- error('File not found')
  43. results:setBit(fileMetadata.RecID)
  44. return nil
  45. end
  46. end
  47. changedMetadata.Pathname=strutil.upToLastOccurrenceOf(changedMetadata.FilePath,'/',false)
  48. changedMetadata.Filename=strutil.fromLastOccurrenceOf(changedMetadata.FilePath,'/',false)
  49. changedMetadata['_UpdateWaveforms']=true
  50. return changedMetadata
  51. end
  52. end
  53. end
  54. --[[ ========================================================== ]]--
  55. processMetadata=setup()
RAW Paste Data