Skip to main content

def add_double_slash(file_path):

  modified_path = ''

  for char in file_path:

    if char == '\\\\':

      modified_path += '\\\\\\\\'

    else:

      modified_path += char

  return modified_path

 

# Example usage

file_path = r'C:\\Users\\Username\\Documents\\file.txt'

modified_file_path = add_double_slash(file_path)

print(modified_file_path)

I'm not quite sure I understand what you want, but if you want a scripted private parameter to add double backslashes to a public parameter containing a filename, you could use the following code in your Python scripted parameter:

import fme
file_path = fme.macroValues.get('FILE_PATH', '')
return file_path.replace('\\', '\\\\')

Be aware that there are no checks on whether FILE_PATH already contains double backslashes.

imageimageimage


I'm not quite sure I understand what you want, but if you want a scripted private parameter to add double backslashes to a public parameter containing a filename, you could use the following code in your Python scripted parameter:

import fme
file_path = fme.macroValues.get('FILE_PATH', '')
return file_path.replace('\\', '\\\\')

Be aware that there are no checks on whether FILE_PATH already contains double backslashes.

imageimageimage

@david_r​  Yes, i want to grab the file path from a public parameter(C:\Users\Username\Documents\file.txt'), modify it through the scripted parameter (Private) by adding double slashes C:\\Users\\Username\\Documents\\file.txt to be used as  value in the transformer PDF2TEXTREADER


@david_r​  Yes, i want to grab the file path from a public parameter(C:\\Users\\Username\\Documents\\file.txt'), modify it through the scripted parameter (Private) by adding double slashes C:\\\\Users\\\\Username\\\\Documents\\\\file.txt to be used as value in the transformer PDF2TEXTREADER

You could also simply drop the Python code and use a ParameterFetcher to retrieve the path, then a StringReplacer to replace \\ with \\\\ before sending it to the PDF2TEXTREADER.


Thank you, @david_r​ !


Reply