Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I remove spaces and special characters from the file name during rendering?

New Here ,
Nov 07, 2014 Nov 07, 2014

I understand that I can set LR_renamingTokensOn to true, but I would like to replace all spaces in the file name with an underscore and remove characters not in the range A-Z and 0-9. What's the easiest way to achieve this?

TOPICS
SDK
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 14, 2014 Nov 14, 2014

Well, if it's an ad-hoc export, i.e. one which your plugin initates via an LrExportSession method, then you can name stuff whatever you want to - just set  LR_tokens to {{custom_token}} then set LR_tokenCustomString to whatever you want (a filtered filename base).

Are you writing a:

* export/publish plugin

* export filter to be used with any export/publish service.

* something else (e.g. menu function), which could use ad-hoc exporting

?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 18, 2014 Nov 18, 2014

Hi Rob,

I can set LR_tokens since the export is done via a custom initiation of LrExportSession, but I find the documentation on it confusing.

I'm writing an export plugin.

Can you provide some sample code for using {{custom_token}} that would run a regular expression on the filename?

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 18, 2014 Nov 18, 2014
LATEST

local photo = catalog:getTargetPhoto()

local sesn = LrExportSession {

    photosToExport = { photo },

    exportSettings = {

        -- ... (determine from export preset) - whatev you want, just be sure you set export directory: LR_export_destinationPathPrefix

        LR_tokens = "{{custom_token}}",

        LR_tokenCustomString = LrPathUtils.removeExtension( photo:getFormattedMetadata( 'fileName' ) ):gsub( "[ %c]", "" ) -- remove spaces and control characters

    },

}

sesn:doExportOnNewTask()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines