comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: file_search: need work around for filenames with square brackets [ ]
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: file_search: need work around for filenames with square brackets [ ] [message #66955] Mon, 15 June 2009 16:36
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
On Mon, 15 Jun 2009 15:09:15 -0700 (PDT), rklein wrote:

> I'd rather go sailing, but could you come back from the tennis court
> please and have a look at this idl journal:
>
> ; IDL Version 7.0, Microsoft Windows (Win32 x86 m32)
> ; Journal File for Administrator@FIFILSTEST
> ; Working directory: C:\FIFILS\Software\FlightSoftware
> ; Date: Mon Jun 15 21:58:08 2009
>
> print,file_search("K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078*")
> ;K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.dff
> ;K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.fit
> ;K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.rff
> print,file_search("K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_\[4,-4\]_lw.df f ")
> print,file_search("K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_/[4,-4/]_lw.df f ")
> print,file_search('"K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.dff"')
>
> Of course, I tried escaping the brackets, but it does not work as you
> can see from the above. May be I should have mentioned that I am
> running on Windows

The square brackets are interpreted as wildcards by file_search. You
can put a single square bracket into square brackets ("[[]" for "["
and "[]]" for "]") and file_search may do what you want.

Example:

print,file_search(" K:\OBSERVATIONS\archiveData\20090403_095540\00098_153217_spi ral162_@0078_[[]4,-4[]]_lw.dff ")

HTH, Heinz
Re: file_search: need work around for filenames with square brackets [ ] [message #66958 is a reply to message #66955] Mon, 15 June 2009 15:26 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> Well, I don't know. I'm running on Windows, too, and
> I have absolutely no problems finding these files:
>
> IDL> files = file_search("c:\temp", '00098_153217*', COUNT=count)
> IDL> print, count
> 2
> IDL> for j=0,1 do print, files[j]
> C:\temp\00098_153217_spiral162_@0078_[4,-4]_lw.dff
> C:\temp\00098_153217_spiral162_@0078_[4,-4]_lw.fit
>
> This is Windows XP and IDL 7.0.4.
>
> I think this might be a Windows problem, not IDL.

Or...

I notice I separated the directory from the file name
and you tried to specify both at once. Does that make
a difference?

David

--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: file_search: need work around for filenames with square brackets [ ] [message #66959 is a reply to message #66958] Mon, 15 June 2009 15:25 Go to previous message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
rklein wrote:
> On Jun 6, 7:03 am, David Fanning <n...@dfanning.com> wrote:
>> rklein writes:
>>> the routines for reading FITS-files in the IDL astro library use
>>> file_search() internally. Now I want to read a file name with square
>>> brackets (as this "[" and " this" ]" ) in it, but file_search seems to
>>> interpret the square brackets as regular expression. Is there a way to
>>> escape the brackets?
>>> Other suggestions?
>>> I don't really want to change the library routines not rename the
>>> files I have to read.
>>
>> Yeah, I hear you. I want to play tennis and hike in
>> the mountains instead of going to work every day. :-(
>>
>> Have you tried a back slash as an escape character?
>
> I'd rather go sailing, but could you come back from the tennis court
> please and have a look at this idl journal:
>
> ; IDL Version 7.0, Microsoft Windows (Win32 x86 m32)
> ; Journal File for Administrator@FIFILSTEST
> ; Working directory: C:\FIFILS\Software\FlightSoftware
> ; Date: Mon Jun 15 21:58:08 2009
>
> print,file_search("K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078*")
> ;K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.dff
> ;K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.fit
> ;K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.rff
> print,file_search("K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_\[4,-4\]_lw.df f ")
> print,file_search("K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_/[4,-4/]_lw.df f ")
> print,file_search('"K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.dff"')
>
> Of course, I tried escaping the brackets, but it does not work as you
> can see from the above. May be I should have mentioned that I am
> running on Windows

In fact, the expansion is performed by the shell (so it's not a
regular
expression kind of thing). So, you should use the character that the
windows shell uses for escaping. I am not sure myself what this
character
is, but you may want to try the ^ character.

Ciao,
Paolo
Re: file_search: need work around for filenames with square brackets [ ] [message #66960 is a reply to message #66959] Mon, 15 June 2009 15:23 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
rklein writes:

> I'd rather go sailing, but could you come back from the tennis court
> please and have a look at this idl journal:
>
> ; IDL Version 7.0, Microsoft Windows (Win32 x86 m32)
> ; Journal File for Administrator@FIFILSTEST
> ; Working directory: C:\FIFILS\Software\FlightSoftware
> ; Date: Mon Jun 15 21:58:08 2009
>
> print,file_search("K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078*")
> ;K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.dff
> ;K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.fit
> ;K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.rff
> print,file_search("K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_\[4,-4\]_lw.df f ")
> print,file_search("K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_/[4,-4/]_lw.df f ")
> print,file_search('"K:\OBSERVATIONS\archiveData
> \20090403_095540\00098_153217_spiral162_@0078_[4,-4]_lw.dff"')
>
> Of course, I tried escaping the brackets, but it does not work as you
> can see from the above. May be I should have mentioned that I am
> running on Windows

Well, I don't know. I'm running on Windows, too, and
I have absolutely no problems finding these files:

IDL> files = file_search("c:\temp", '00098_153217*', COUNT=count)
IDL> print, count
2
IDL> for j=0,1 do print, files[j]
C:\temp\00098_153217_spiral162_@0078_[4,-4]_lw.dff
C:\temp\00098_153217_spiral162_@0078_[4,-4]_lw.fit

This is Windows XP and IDL 7.0.4.

I think this might be a Windows problem, not IDL.

Cheers,

David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDLDOC 3.2 Index page not as interesting as it could be...
Next Topic: update variable in structure

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 12:12:43 PDT 2025

Total time taken to generate the page: 1.04468 seconds