Re: Spaces in Mac file names [message #83991] |
Sat, 13 April 2013 21:19 |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 4/13/13 12:33 PM, Jeff N. wrote:
> On Saturday, April 13, 2013 1:30:22 PM UTC-4, kagol...@lbl.gov wrote:
>> Regarding spaces in Mac file and directory names: I know this is an old topic, but is there a generally accepted method, or a library function in someone's IDL library, to take a file name as input and output ac copy with the spaces escaped properly with backslashes?
>>
>>
>>
>> In other words, take
>>
>> /this/directory/has spaces/youknow.txt
>>
>> and output
>>
>> /this/directory/has\ spaces/youknow.txt
>>
>>
>>
>> I need this for a spawn command to work on arbitrary files. Thanks!
>
> I usually do this:
>
> ENVI> path = '/this/directory/has spaces/youknow.txt'
> ENVI> print, strjoin(strsplit(path, ' ', /extract), '\ ')
> /this/directory/has\ spaces/youknow.txt
>
Careful, multiple spaces won't be treated correctly. Use /PRESERVE_NULL:
IDL> path = '/this/directory/has spaces/you know.txt'
IDL> print, strjoin(strsplit(path, ' ', /extract), '\ ')
/this/directory/has\ spaces/you\ know.txt
IDL> print, strjoin(strsplit(path, ' ', /extract, /preserve_null), '\ ')
/this/directory/has\ spaces/you\ \ know.txt
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
|
|
|
Re: Spaces in Mac file names [message #83992 is a reply to message #83991] |
Sat, 13 April 2013 11:33  |
jeffnettles4870
Messages: 111 Registered: October 2006
|
Senior Member |
|
|
On Saturday, April 13, 2013 1:30:22 PM UTC-4, kagol...@lbl.gov wrote:
> Regarding spaces in Mac file and directory names: I know this is an old topic, but is there a generally accepted method, or a library function in someone's IDL library, to take a file name as input and output ac copy with the spaces escaped properly with backslashes?
>
>
>
> In other words, take
>
> /this/directory/has spaces/youknow.txt
>
> and output
>
> /this/directory/has\ spaces/youknow.txt
>
>
>
> I need this for a spawn command to work on arbitrary files. Thanks!
I usually do this:
ENVI> path = '/this/directory/has spaces/youknow.txt'
ENVI> print, strjoin(strsplit(path, ' ', /extract), '\ ')
/this/directory/has\ spaces/youknow.txt
|
|
|