diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index 368570ff8a..9e974e9b06 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include namespace GUI { @@ -340,11 +339,11 @@ void FilePicker::model_did_update(unsigned) void FilePicker::on_file_return() { auto path = m_filename_textbox->text(); - if (!path.starts_with('/')) { + if (!path.starts_with('/')) path = LexicalPath::join(m_model->root_path(), path).string(); - } - bool file_exists = FileSystem::exists(path); + auto stat_or_error = Core::System::stat(path); + bool file_exists = !stat_or_error.is_error(); if (!file_exists && (m_mode == Mode::Open || m_mode == Mode::OpenFolder)) { (void)MessageBox::try_show_error(this, DeprecatedString::formatted("Opening \"{}\" failed: {}", m_filename_textbox->text(), Error::from_errno(ENOENT))); @@ -360,6 +359,13 @@ void FilePicker::on_file_return() return; } + // If the entered filename matches an existing directory, traverse into it + if (file_exists && m_mode != Mode::OpenFolder && S_ISDIR(stat_or_error.value().st_mode)) { + m_filename_textbox->clear(); + set_path(path); + return; + } + m_selected_file = path; done(ExecResult::OK); }