diff --git a/modules/juce_core/files/juce_File.cpp b/modules/juce_core/files/juce_File.cpp index ce076d85fa..e6ed109022 100644 --- a/modules/juce_core/files/juce_File.cpp +++ b/modules/juce_core/files/juce_File.cpp @@ -103,6 +103,11 @@ static String removeEllipsis (const String& path) return path; } +bool File::isRoot() const +{ + return fullPath.isNotEmpty() && *this == getParentDirectory(); +} + String File::parseAbsolutePath (const String& p) { if (p.isEmpty()) diff --git a/modules/juce_core/files/juce_File.h b/modules/juce_core/files/juce_File.h index 35d5749d6c..8f18d99f1b 100644 --- a/modules/juce_core/files/juce_File.h +++ b/modules/juce_core/files/juce_File.h @@ -120,6 +120,14 @@ public: */ bool isDirectory() const; + /** Checks whether the path of this file represents the root of a file system, + irrespective of its existance. + + This will return true for "C:", "D:", etc on Windows and "/" on other + platforms. + */ + bool isRoot() const; + /** Returns the size of the file in bytes. @returns the number of bytes in the file, or 0 if it doesn't exist. diff --git a/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp b/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp index 9497499998..728a4c6d36 100644 --- a/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp +++ b/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp @@ -164,7 +164,7 @@ void FileChooser::showPlatformDialog (Array& results, const String& title_ auto parentDirectory = currentFileOrDirectory.getParentDirectory(); // Handle nonexistent root directories in the same way as existing ones - if (currentFileOrDirectory.isDirectory() || parentDirectory == currentFileOrDirectory) + if (currentFileOrDirectory.isDirectory() || currentFileOrDirectory.isRoot()) { info.initialPath = currentFileOrDirectory.getFullPathName(); }