diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 16b687ea1..780b33c00 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -1106,6 +1106,10 @@ void _OS::dump_resources_to_file(const String &p_file) { OS::get_singleton()->dump_resources_to_file(p_file.utf8().get_data()); } +Error _OS::move_to_trash(const String &p_path) const { + return OS::get_singleton()->move_to_trash(p_path); +} + String _OS::get_user_data_dir() const { return OS::get_singleton()->get_user_data_dir(); }; @@ -1404,6 +1408,7 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &_OS::get_static_memory_peak_usage); ClassDB::bind_method(D_METHOD("get_dynamic_memory_usage"), &_OS::get_dynamic_memory_usage); + ClassDB::bind_method(D_METHOD("move_to_trash", "path"), &_OS::move_to_trash); ClassDB::bind_method(D_METHOD("get_user_data_dir"), &_OS::get_user_data_dir); ClassDB::bind_method(D_METHOD("get_system_dir", "dir", "shared_storage"), &_OS::get_system_dir, DEFVAL(true)); ClassDB::bind_method(D_METHOD("get_config_dir"), &_OS::get_config_dir); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 8fc23d653..8d982c215 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -353,6 +353,7 @@ public: String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const; + Error move_to_trash(const String &p_path) const; String get_user_data_dir() const; String get_config_dir() const; String get_data_dir() const; diff --git a/doc/classes/Directory.xml b/doc/classes/Directory.xml index ec80286eb..5ffbd6274 100644 --- a/doc/classes/Directory.xml +++ b/doc/classes/Directory.xml @@ -153,7 +153,8 @@ - Deletes the target file or an empty directory. The argument can be relative to the current directory, or an absolute path. If the target directory is not empty, the operation will fail. + Permanently deletes the target file or an empty directory. The argument can be relative to the current directory, or an absolute path. If the target directory is not empty, the operation will fail. + If you don't want to delete the file/directory permanently, use [method OS.move_to_trash] instead. Returns one of the [enum Error] code constants ([code]OK[/code] on success). diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index bd223a40c..4e74e1bc7 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -773,6 +773,14 @@ [b]Note:[/b] This method is implemented on Android, iOS, Linux, macOS and Windows. + + + + + Moves the file or directory to the system's recycle bin. See also [method Directory.remove]. + [b]Note:[/b] If the user has disabled the recycle bin on their system, the file will be permanently deleted instead. + +