I need to process a bunch of files that have a # character in their name. Those files are on a Windows XP box. The little script that I wrote in Fantom is not finding them because is changing the path by either dropping everything after the # character or by escaping it and changing the separators. This sample class shows what is happening:
Please pay special attention to the last 2 echo statements.
Any ideas, please?
tcolarWed 16 Jan 2013
Use
File.os("/tmp/foo/bar_#_qux")
In "normal" uri's (web) the # is used for anchors and not considered part of the actual path so it gets dropped probably.
ortizgiraldoWed 16 Jan 2013
Thanks @tcolar, that worked and now I can access the files.
I'd like to add that if you need to print the path echo(File.os("/tmp/foo/bar_#_qux")) won't work and you need to invoke osPath on the file, e.g. echo(File.os("/tmp/foo/bar_#_qux").osPath) to get it right.
brianWed 16 Jan 2013
Since we treat files as URIs, the pound char is normally treated as the fragment identifier. In a path where this is not the case, then you need to backslash escape it:
uri := `/tmp/foo/bar_\#_qux`
ortizgiraldoThu 17 Jan 2013
Thanks @brian for the explanation. I'll keep the Str form though, just to avoid having to escape dynamically generated paths. The escaped form also gives me some unexpected results in the sample class above.
ortizgiraldo Wed 16 Jan 2013
Hi,
I need to process a bunch of files that have a # character in their name. Those files are on a Windows XP box. The little script that I wrote in Fantom is not finding them because is changing the path by either dropping everything after the # character or by escaping it and changing the separators. This sample class shows what is happening:
Please pay special attention to the last 2 echo statements.
Any ideas, please?
tcolar Wed 16 Jan 2013
Use
In "normal" uri's (web) the # is used for anchors and not considered part of the actual path so it gets dropped probably.
ortizgiraldo Wed 16 Jan 2013
Thanks @tcolar, that worked and now I can access the files.
I'd like to add that if you need to print the path
echo(File.os("/tmp/foo/bar_#_qux"))
won't work and you need to invokeosPath
on the file, e.g.echo(File.os("/tmp/foo/bar_#_qux").osPath)
to get it right.brian Wed 16 Jan 2013
Since we treat files as URIs, the pound char is normally treated as the fragment identifier. In a path where this is not the case, then you need to backslash escape it:
ortizgiraldo Thu 17 Jan 2013
Thanks @brian for the explanation. I'll keep the Str form though, just to avoid having to escape dynamically generated paths. The escaped form also gives me some unexpected results in the sample class above.