Locating Files in Directory Structures

QUESTION: I have a large IDL application that I distribute to a number of people, some of whom may be running IDL on different operating systems than I am. My problem is that I never know where the directories I distribute to them are going to end up in their directory system. I only know that they will be on their IDL path. But I need to know the location of certain directories in my IDL distribution, either because they contain specific data files or because there are certain resources in particular directories. How can I determine this information in a machine and operating system independent way?

ANSWER: Today's answer was offered to the IDL newsgroup by J.D. Smith, who always seems to have these kinds of tricks up his sleeve. I've paraphased a little bit.

I solve this problem with a method that avoids any machine-specific information or specific knowledge about file path delimiters, etc. The method requires placing a "marker" file in the directory you are interested in locating. This can either be a real file, or it can be a dummy file with nothing in it. It must, however, end in a ".pro" file extension. This is absolutely critical. Don't forget it.

For example, suppose I wish to identify the directory where I have stored calibration tables in the user's directory structure. In my calibration table directory, I have placed the file irs_calib_dir_marker.pro. I find the directory with this code:

   source = (Routine_Info('irs_calib_dir_marker', /SOURCE)).PATH
   calibDir = Strmid(source, 0, Strpos(source, Path_Sep(), /REVERSE_SEARCH))

The advantage of this method is that your run-time required data or directory will be found with the associated routine independent of how IDL was started, and even if the user has severely butchered the file structure of your distribution (for example, by moving various directories around from the way you had them organized).

You can also create directories or files relative to this in a platform-independent way using the Filepath command. For example:

   file = Filepath(ROOT_DIR=calibDir, SUBDIR='irs_tables', 'irs_89745.tbl')

Google
 
Web Coyote's Guide to IDL Programming