A lot of what I do in IDL involves using paths all over the place, the problem is, I want my code to work in Windows or Linux, but we of course have that old problem of / v \.
At the top of my IDL program I have usually defined a root directory of where we will be working, but during the program I might want to go to a subdirectory of (let’s say) y2011 and then d253, i.e. on Windows:
and on Linux:
But I don’t want to have to define what OS I happen to be working in, so here is a little function to make this process easy, detectos. The use of this function is very easy, lets assume we are running our IDL program on Windows:
path='rootdir/y2011/d253/' path=detectos(path) PRINT,path rootdir\y2011\d253\
Of course you also could have just as easily used it (and tested it) in one line:
I usually call ‘detectos’ every time I create a path, to make sure that the path is in the correct format for the OS I am using.