Repository: godotengine/godot (language: cpp)

Issue:
Folder Creation fails(Show in File System) : New Folder (Could not create folder: Can't create)
### Tested versions

Godot v4.4.stable - Windows 10 (build 19045) - Multi-window, 1 monitor - OpenGL 3 (Compatibility) - NVIDIA GeForce GTX 1650 (NVIDIA; 32.0.15.7260) - AMD Ryzen 3 3100 4-Core Processor (8 threads)

### System information

Godot v4.4.stable - Windows 10 (build 19045) - Multi-window, 1 monitor - OpenGL 3 (Compatibility) - NVIDIA GeForce GTX 1650 (NVIDIA; 32.0.15.7260) - AMD Ryzen 3 3100 4-Core Processor (8 threads)

### Issue description

Folder Creation fails when show in File System clicked and then right clicked > New Folder (Could not create folder: Can't create)

### Steps to reproduce

From Scene Tab > Click Show in File System 
Right Click in File System > New Folder 
(Could not create folder: Can't create)

### Minimal reproduction project (MRP)

Any simple project would work with a saved scene.


Discussion / hints:
Confirmed repro, but it seems like it only happens when it's in a subdirectory, and the Show in File System isn't necessary. Just have a file that isn't in the root selected in the FileSystem dock and try to right click it and create a folder. Creating files that way works, and creating folders off right clicking a file in the root work.
Oh, I'll check that too 👍

Fix patch:
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index 16a7578d8acd..2f960beccac9 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -3437,7 +3437,7 @@ Error EditorFileSystem::make_dir_recursive(const String &p_path, const String &p
 	ERR_FAIL_NULL_V(parent, ERR_FILE_NOT_FOUND);
 	folders_to_sort.insert(parent->get_instance_id());
 
-	const PackedStringArray folders = p_path.trim_prefix(path).trim_suffix("/").split("/");
+	const PackedStringArray folders = p_path.trim_prefix(path).split("/", false);
 	for (const String &folder : folders) {
 		const int current = parent->find_dir_index(folder);
 		if (current > -1) {
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 67c9f0dba2ba..e7c49b2a874c 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -2743,7 +2743,13 @@ void FileSystemDock::focus_on_filter() {
 }
 
 void FileSystemDock::create_directory(const String &p_path, const String &p_base_dir) {
-	Error err = EditorFileSystem::get_singleton()->make_dir_recursive(p_path.trim_prefix(p_base_dir), p_base_dir);
+	String trimmed_path = p_path;
+	if (!p_base_dir.is_empty()) {
+		// Trims off the joining '/' if the base didn't end with one. If the base did have it
+		// and there's two slashes, the empty directory is safe to trim off anyways.
+		trimmed_path = trimmed_path.trim_prefix(p_base_dir).trim_prefix("/");
+	}
+	Error err = EditorFileSystem::get_singleton()->make_dir_recursive(trimmed_path, p_base_dir);
 	if (err != OK) {
 		EditorNode::get_singleton()->show_warning(vformat(TTR("Could not create folder: %s"), error_names[err]));
 	}


Test patch: