1111#include < fstream>
1212#include < ll/api/io/FileUtils.h>
1313#include < string>
14+ #include < system_error>
1415
1516using namespace std ::filesystem;
1617
@@ -113,7 +114,7 @@ FileClass* FileClass::constructor(const Arguments& args) {
113114 string path = args[0 ].toStr ();
114115 std::optional<std::string> dirPath = getDirectoryPath (path);
115116 if (dirPath.has_value ()) {
116- std::filesystem::create_directory (dirPath.value ());
117+ std::filesystem::create_directories (dirPath.value ());
117118 } else {
118119 LOG_ERROR_WITH_SCRIPT_INFO (" Fail to create directory " + dirPath.value () + " !\n " );
119120 return nullptr ;
@@ -520,7 +521,7 @@ Local<Value> DirCreate(const Arguments& args) {
520521 CHECK_ARG_TYPE (args[0 ], ValueKind::kString );
521522
522523 try {
523- return Boolean::newBoolean (std::filesystem::create_directory (args[0 ].toStr ()));
524+ return Boolean::newBoolean (std::filesystem::create_directories (args[0 ].toStr ()));
524525 } catch (const filesystem_error& e) {
525526 LOG_ERROR_WITH_SCRIPT_INFO (" Fail to Create Dir " + args[0 ].asString ().toString () + " !\n " );
526527 return Boolean::newBoolean (false );
@@ -678,7 +679,12 @@ Local<Value> FileWriteTo(const Arguments& args) {
678679 string path = args[0 ].toStr ();
679680 std::optional<std::string> dirPath = getDirectoryPath (path);
680681 if (dirPath.has_value ()) {
681- std::filesystem::create_directory (dirPath.value ());
682+ std::error_code code;
683+ std::filesystem::create_directories (dirPath.value (), code);
684+ if (code) {
685+ LOG_ERROR_WITH_SCRIPT_INFO (" Fail to create directory " + dirPath.value () + " !\n " );
686+ return Boolean::newBoolean (false );
687+ }
682688 } else {
683689 LOG_ERROR_WITH_SCRIPT_INFO (" Fail to create directory " + dirPath.value () + " !\n " );
684690 return Boolean::newBoolean (false );
@@ -697,7 +703,12 @@ Local<Value> FileWriteLine(const Arguments& args) {
697703 string path = args[0 ].toStr ();
698704 std::optional<std::string> dirPath = getDirectoryPath (path);
699705 if (dirPath.has_value ()) {
700- std::filesystem::create_directory (dirPath.value ());
706+ std::error_code code;
707+ std::filesystem::create_directories (dirPath.value (), code);
708+ if (code) {
709+ LOG_ERROR_WITH_SCRIPT_INFO (" Fail to create directory " + dirPath.value () + " !\n " );
710+ return Boolean::newBoolean (false );
711+ }
701712 } else {
702713 LOG_ERROR_WITH_SCRIPT_INFO (" Fail to create directory " + dirPath.value () + " !\n " );
703714 return Boolean::newBoolean (false );
@@ -723,7 +734,12 @@ Local<Value> OpenFile(const Arguments& args) {
723734 string path = args[0 ].toStr ();
724735 std::optional<std::string> dirPath = getDirectoryPath (path);
725736 if (dirPath.has_value ()) {
726- std::filesystem::create_directory (dirPath.value ());
737+ std::error_code code;
738+ std::filesystem::create_directories (dirPath.value (), code);
739+ if (code) {
740+ LOG_ERROR_WITH_SCRIPT_INFO (" Fail to create directory " + dirPath.value () + " !\n " );
741+ return Boolean::newBoolean (false );
742+ }
727743 } else {
728744 LOG_ERROR_WITH_SCRIPT_INFO (" Fail to create directory " + dirPath.value () + " !\n " );
729745 return {};
0 commit comments