PixInsight Forum (historical)
Software Development => PCL and PJSR Development => Topic started by: bitli on 2015 February 01 07:49:20
-
I need to get the full directory (with drive and whatever) of a file (this is to initialize the initialPath of FileDialog). It seems that on windows File.extractDirectory does not return the drive part. Is there a method to get this information which is OS independent and does not rely on parsing the path ?
Thanks
-- bitli
-
Hi Bitli,
In previous scripts I used File.extractDrive(name) + File.extractDirectory(name). Seems to work on Win and Mac, don't know about other platforms.
In new script I am working on I don't bother, as PI seems to remember and use a directory by default most of the time. However if the saved directory no longer exists PI reverts to its install directory, which I find annoying. I wish PI would search up the directory path for an existing directory, and stop there. IMO this would save navigation time.
Mike
-
Thanks Mike, this will do (I will check on Windows)
This is to store the 'configurations' (rule sets) for FITSFileManager, so they are usually in a directory different from the images, so it would make sense to have a different default I will see how it works,
-- bitli
-
The correct way to implement this is as follows:
function getDirectoryWithDriveLetter( a_path )
{
let path = File.windowsPathToUnix( a_path );
return File.extractDrive( path ) + File.extractDirectory( path );
}
This function is portable to all supported platforms. A drive specification "<u>:" will be included if it is present in the specified path. UNIX directory separators "/" will be used on all platforms.