Escaping shell script paths (was: Photo Processing , Gallery and IPTC Data app)
Ken Ray
kray at sonsothunder.com
Sat Feb 2 21:57:46 EST 2008
On Fri, 1 Feb 2008 18:52:28 +1000, Ian Wood wrote:
> Oops. Just discovered that the above function doesn't cope with file
> paths that contain any kind of quote mark.
>
> The following function should work better, escaping characters rather
> than putting quote marks around the whole path.
Here's the function I use, which works for both Mac and Windows:
function stsFormatPath pPath,pPlatform
-- assumes a full "/"-delimited path
switch pPlatform
case "MacOSX"
case "Unix"
put "\" & space & quote & "'`<>!;()[]?#$^&*=" into tSpecialChars
repeat for each char tChar in tSpecialChars
replace tChar with ("\" & tChar) in pPath
end repeat
break
case "Win32"
set the itemDel to "/"
put item -1 of pPath into tFile
put "\/:*?" & quote & "<>|" into tSpecialChars
repeat for each char tChar in tSpecialChars
replace tChar with ("-") in tFile
end repeat
put tFile into item -1 of pPath
replace "/" with "\" in pPath
break
end switch
return pPath
end stsFormatPath
Hope this helps,
Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
More information about the use-livecode
mailing list