Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Change FilePath
- -- July 16, 2012.
- -- Written by Justin Drury
- -- specialized version that doesn't change the waveform table...
- allowUndo=true
- --[[ ???????
- changedMetadata['_ChangeFilePath']=true -- a little flag to tell soundminer to go and build pathname & filepath hash from the filepath
- --changedMetadata.['_UpdateWaveforms']=aw:getToggleButtonState() -- another flag to tell SM to also update the waveform table
- ]]--
- -- This uses a Lua capability called closure.
- results=smbigint()
- function setup()
- local validate=userPrefs.validateFilePath
- print(type(userPrefs.validateFilePath),userPrefs.validateFilePath,validate)
- aw=smalertwindow('FilePath Change','This will change the filepath for the selected records.')
- aw:addTextEditor(userPrefs.lastFilePathFind,'Find:','findbox',false)
- aw:addTextEditor(userPrefs.lastFilePathReplace,'Replace:','replacebox',false)
- aw:addToggleButton("Check that file exists before changing",{250,30},'validate',validate)
- aw:addCancelButton()
- aw:addOkButton()
- if aw:runAlert()==1 then
- local findString=aw:getTextEditorContents('findbox')
- userPrefs.lastFilePathFind=findString -- save this pref for recall later
- local replaceString=aw:getTextEditorContents('replacebox')
- userPrefs.lastFilePathReplace=replaceString
- userPrefs.validateFilePath=aw:getToggleButtonState('validate')
- if findString==string.char() or replaceString==string.char() then
- return nil
- end
- return function(fileMetadata)
- local changedMetadata={}
- changedMetadata.FilePath=strutil.replace(fileMetadata.FilePath,findString,replaceString)
- if userPrefs.validateFilePath then
- local fileCheck=smfile(changedMetadata.FilePath)
- if not fileCheck:existsAsFile() then
- -- error('File not found')
- results:setBit(fileMetadata.RecID)
- return nil
- end
- end
- changedMetadata.Pathname=strutil.upToLastOccurrenceOf(changedMetadata.FilePath,'/',false)
- changedMetadata.Filename=strutil.fromLastOccurrenceOf(changedMetadata.FilePath,'/',false)
- changedMetadata['_UpdateWaveforms']=true
- return changedMetadata
- end
- end
- end
- --[[ ========================================================== ]]--
- processMetadata=setup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement