Skip to main content
Solved

Construct a URL from a Windows file path?


lacy
Contributor
  • Contributor

I'll be the first to admit this may be a dumb newbie question, but I'm struggling!

 

I have an input field that contains a file path like the following:

q:\\staging\\incoming\\1930s\\WI\\Sauk\\1937\\Sauk_WI_WU_11_908_19370707.tif

I need to construct a URL to the file as referenced in a URL, and dump it into another field:

https://server.com/1930s/WI/Sauk/1937/Sauk_WI_WU_11_908_19370707.tif

 

My conceptual approach has been to use string processing to replace q:\\staging\\incoming with https://server.com, and then replace backslashes with forward slashes.

 

Well, you can see where this is going... the slashes and backslashes are wreaking havoc.

 

For example, I've tried various combinations to escape the \\, like:

@ReplaceString(@Value(inputpath),"/\\","/")

... but I either get no results, or a syntax notice.

 

Am I even in the ballpark?? I'd love some suggestions on how to approach this issue.

 

 

Best answer by dustin

Have you tried the StringReplacer?

View original
Did this help you find an answer to your question?

6 replies

dustin
Influencer
Forum|alt.badge.img+30
  • Influencer
  • Best Answer
  • April 11, 2023

Have you tried the StringReplacer?


lacy
Contributor
  • Author
  • Contributor
  • April 11, 2023

Thanks. I just played with the StringReplacer transformer, and it looks like that will work fine with no fuss. This is where my ignorance/newness of FME shows through. I'm attempting to handle many of my manipulations in the Attribute Manager transformer. That is, I'm still trying to understand when to use a transformer like StringReplacer vs string function like ReplaceString.


dustin
Influencer
Forum|alt.badge.img+30
  • Influencer
  • April 12, 2023
lacy wrote:

Thanks. I just played with the StringReplacer transformer, and it looks like that will work fine with no fuss. This is where my ignorance/newness of FME shows through. I'm attempting to handle many of my manipulations in the Attribute Manager transformer. That is, I'm still trying to understand when to use a transformer like StringReplacer vs string function like ReplaceString.

The ReplaceString function is handy, and I use it all the time actually. But when you have special characters like backslashes, commas or apostrophes to replace, it can get confusing trying to escape these in the syntax. That's when I usually use the StringReplacer.


redgeographics
Celebrity
Forum|alt.badge.img+49
lacy wrote:

Thanks. I just played with the StringReplacer transformer, and it looks like that will work fine with no fuss. This is where my ignorance/newness of FME shows through. I'm attempting to handle many of my manipulations in the Attribute Manager transformer. That is, I'm still trying to understand when to use a transformer like StringReplacer vs string function like ReplaceString.

In more general terms, while you can do a lot of stuff using functions in the AttributeManager I find it's often easier to manage if you use separate transformers for it. In this particular case the StringReplacer is definitely easier to set up. Just 2 of them would do the trick, no need to use Regular Expressions or anything.


lacy
Contributor
  • Author
  • Contributor
  • April 12, 2023

Thanks for the tips, much appreciated!


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • April 12, 2023

No need to quote or escape backslashes

@ReplaceString(@Value(inputpath),\,/)

image


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings