X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 10 Jul 2012 07:12 AM by  anon
Search a dir and not its subdirs for files based on extension?
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
10 Jul 2012 07:12 AM
    hi there, I'm trying to figure out if there is a way to return only the .txt files from a specified dir and not the subdirs within. For example. I have a dir c:\data\ containing text.txt and another dir called 'other' In c:\data\other\ is 2 other .txt files. I am using file_search but I only want to retrieve the full path for text.txt and not the other .txt files. Another way to look at it is, is it possible to only search a dir and not its subdirs for files based on extension? I'm pretty new to IDL but have used Matlab quite a bit. I know the Matlab function for this but is there an equivalent in IDL... Thanks. Norris

    Deleted User



    New Member


    Posts:
    New Member


    --
    10 Jul 2012 12:16 PM
    Hi Norris, One way is to 'hard code' the directory before doing a file search. It could look something like this: IDL> cd, 'c:\TEMP\' IDL> t=file_search(*.txt) For something more explicit you may have to use a combination of IDL functions. In the Help Contents search box type in the following to see what is available: file_

    Deleted User



    New Member


    Posts:1
    New Member


    --
    11 Jul 2012 12:49 AM
    Hi, print,file_search('c:\data\*.txt') should do it in one line.

    Deleted User



    New Member


    Posts:
    New Member


    --
    12 Jul 2012 04:40 AM
    Thanks! that did the trick. My mistake was trying file_search(path, *.txt) so it was searching in all subdirs. Silly mistake.
    You are not authorized to post a reply.