Page 1 of 1

How do you handle Illegal Characters?

Posted: Fri Aug 11, 2017 1:04 am
by cwswitch
Illeg&ampl Ch&amprachters

How do you guys handle files with funny characters in them please?

My fail point is when I inject. First there is an error that the file does not exist, followed by a later error that my xml is now orphaned.

The issue each time is a funny character, like an "&" in the file name.

Re: How do you handle Illegal Characters?

Posted: Fri Aug 11, 2017 2:36 am
by gabrielp
Here is a script that scrubs them from private data variables: https://github.com/open-automation/swit ... e-scrubber

Re: How do you handle Illegal Characters?

Posted: Fri Aug 11, 2017 4:41 am
by cwswitch
Thanks

Your forum posts and scripts are very clear and useful. I could not get by without your private data script! I use that all the time for sorting jobs.

I'm a bit unclear how I use this for injecting a job with an "&" in the filename

Example error I'm trying to work around

Code: Select all

Error,Inject job,141032.01.xml,Failed to inject job: file or folder 'foo\141032.01\A5 SPEND&SAVE - final.pdf' does not exist

Re: How do you handle Illegal Characters?

Posted: Tue Aug 15, 2017 10:00 am
by jan_suhr
If the problematic characters are in the filename and Switch has problem finding the files Switch can't change the file name until the file is in the Switch system.

What are the file systems? Are the files on another system than the Switch installation?


Jan

Re: How do you handle Illegal Characters?

Posted: Wed Aug 16, 2017 5:49 am
by cwswitch
Thanks,

Very good point that Switch can't work on files it can't find.. I feel silly for even considering that!

The files are on a Windows Server which I access over the network.

I suppose I was wondering whether I could manipulate the XML or pull the path into Private Data (as Gabriel seemed to be suggesting) then clean it up and try my Inject.

Switch is saying

Code: Select all

Failed to inject job: foo/bar&baz.pdf' does not exist
I guess Gabriel is saying to pull the file path into a Private Data key, clean it, then call the Inject with the clean path - but I'm at loss to how.

Re: How do you handle Illegal Characters?

Posted: Wed Aug 16, 2017 3:24 pm
by gabrielp
cwswitch wrote: I guess Gabriel is saying to pull the file path into a Private Data key, clean it, then call the Inject with the clean path - but I'm at loss to how.
I would probably aim to figure out how the files are getting there in the first place, then have Switch do that, cleaning the file names before I archive them. Then later on, they can be injected more easily.

Code: Select all

Failed to inject job: foo/bar&baz.pdf' does not exist
I'm guessing that you're getting this value from an XML dataset or something. So I bet if you wrote a script to decode HTML entities, you could then use the normal inject to get these files.

Re: How do you handle Illegal Characters?

Posted: Wed Aug 16, 2017 4:06 pm
by jan_suhr
Shouldn't Switch decode the XML, the & is illegal in XML and is written as &. If you get it from a Metadata variable it should be correctly applied as a file path in Switch. If not you always have the Search field in the variables were you can do a RegEx to change the & to & and then the path should work.


Jan