Quoting filenames with single quotes in the names problem

Q&A's, tips, howto's
Locked
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Quoting filenames with single quotes in the names problem

Post by cormullion »

I've discovered that my approach to quoting filenames with single quotes isn't a good idea, since I've discovered loads of filenames that have single quotes in their names. :-) So I want to use (format " %s " file-name) and surround the %s with something other than single quotes... Is it possible to do something that's both acceptable to newLISP and the Unix shell?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

You could try double quotes in UNIX for delimiting file names. To allow " in newLISP inside a string you have several ways to do it:

Code: Select all

(format "\"%s\"" file-name)

(format {"%s"} file-name)

(format [text]"%s"[/text] file-name)
This way UNIX will not trip over single quotes part of the filename. I think this would also work on Win32.

Lutz

ps: both {,} and [text],[/text] suppress escape character processing inside the string.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Yes, these changes work OK, as far as I can see. Thanks!

Locked