Skip to main content

Occasionally the Folder (existing) parameter will change a backslash in the folder path to a forward slash when the feature is is shown in the table. This creates a major problem for reading, writing and comparing to this folder. Is there anyway to make sure this doesnt happen?

Can you give a concrete example why this is an issue? Recent versions of Windows accepts both backslashes and forward slashes in paths.

You can of course also use a StringPairReplacer to normalize the slashes in your paths.


Can you give a concrete example why this is an issue? Recent versions of Windows accepts both backslashes and forward slashes in paths.

You can of course also use a StringPairReplacer to normalize the slashes in your paths.

@david_r , thanks for your reply. I use a tester in FME to test various path directories against each other. Sometimes there is a forward slash and sometimes there isnt.

I will use the StringPairReplacer as per your recommendation (or a StringReplacer).

I was just wondering if you know why this happens? I cant figure out what the reason behind it is, it seems random.

Thanks again,

Philip


@david_r , thanks for your reply. I use a tester in FME to test various path directories against each other. Sometimes there is a forward slash and sometimes there isnt.

I will use the StringPairReplacer as per your recommendation (or a StringReplacer).

I was just wondering if you know why this happens? I cant figure out what the reason behind it is, it seems random.

Thanks again,

Philip

I don't know, but I suspect that it's linked to certain modules in FME that are trying to be operating system agnostic.


This was causing me grief too. I was trying to pass a folder containing a file geodatabase parent path as a parameter to arcpy using a system caller.

 

Its all down to FME automatically replacing the beginning of paths within a workspace which match the workspaces's folder with $(FME_MF_DIR).

Documented here: https://community.safe.com/s/article/fme-mf-dir-environment-variable

 

Unfortunately the FME parameter adds a trailing forward slash onto the end of the $(FME_MF_DIR) parameter, even on windows.

 

My user Parameter containing desired Path for Geodatabase folder 

$(TemporaryGeoDatabaseLocation) = D:\\BatchProcesses\\ServiceArea\\TemporaryData

 

My FME workspace was in D:\\BatchProcesses\\ServiceArea\\

 

So $(FME_MF_DIR) = D:\\BatchProcesses\\ServiceArea/

Causing the parameter to be rewritten as: $(FME_MF_DIR)TemporaryData

 

But get evaluated as D:\\BatchProcesses\\ServiceArea/TemporaryData 

 

This was not compatible with arcpy when passed via a system caller in my use case.

 

After much digging about here is my workaround:

 

Option 1: This is a poor solution as it is hardcoded in every instance. Use the FME_MF_DIR parameter and TrimRight command to strip the trailing backslash on the workspace folder and hardcode "\\TemporaryData" into any use of the folder.

 

@TrimRight($(FME_MF_DIR),"//")\\TemporaryData

 

 

Option 2: Wrap any use of your original parameter with a string replacer to change any forwardslashes back to a backslash.

 

@ReplaceString($(TemporaryGeoDatabaseLocation),"/",\\,caseSensitive=TRUE)

 

Note: the backslash is an escape character and must not be included in double quotes as it will escape the ending quote and cause an error.

 


This was causing me grief too. I was trying to pass a folder containing a file geodatabase parent path as a parameter to arcpy using a system caller.

 

Its all down to FME automatically replacing the beginning of paths within a workspace which match the workspaces's folder with $(FME_MF_DIR).

Documented here: https://community.safe.com/s/article/fme-mf-dir-environment-variable 

 

Unfortunately the FME parameter adds a trailing forward slash onto the end of the $(FME_MF_DIR) parameter, even on windows.

 

My user Parameter containing desired Path for Geodatabase folder 

$(TemporaryGeoDatabaseLocation) = D:\BatchProcesses\ServiceArea\TemporaryData

 

My FME workspace was in D:\BatchProcesses\ServiceArea\

 

So $(FME_MF_DIR) = D:\BatchProcesses\ServiceArea/

Causing the parameter to be rewritten as: $(FME_MF_DIR)TemporaryData

 

But get evaluated as D:\BatchProcesses\ServiceArea/TemporaryData 

 

This was not compatible with arcpy when passed via a system caller in my use case.

 

After much digging about here is my workaround:

 

Option 1: This is a poor solution as it is hardcoded in every instance. Use the FME_MF_DIR parameter and TrimRight command to strip the trailing backslash on the workspace folder and hardcode "\TemporaryData" into any use of the folder.

 

@TrimRight($(FME_MF_DIR),"//")\TemporaryData

 

 

Option 2: Wrap any use of your original parameter with a string replacer to change any forwardslashes back to a backslash.

 

@ReplaceString($(TemporaryGeoDatabaseLocation),"/",\,caseSensitive=TRUE)

 

Note: the backslash is an escape character and must not be included in double quotes as it will escape the ending quote and cause an error.

 

There's actually a dedicated helper function in the "fme" Python module for this.

Sample usage:

import fme
 
def get_full_path(feature):
    path = feature.getAttribute('path')
    if path:
        absolute_path = fme.getAbsolutePath(path)
        feature.setAttribute('absolute_path', absolute_path)

It will read the feature attribute "path" and return "absolute_path". Sample input:

$(FME_MF_DIR)\test\\123/full\path/

Sample output:

C:\Users\username\AppData\Local\Temp\test\123\full\path

 


Reply