@@ -26,6 +26,7 @@ Date: January 2012
26
26
#include < io.h>
27
27
#include < windows.h>
28
28
#include < direct.h>
29
+ #include < util/unicode.h>
29
30
#define chdir _chdir
30
31
#define popen _popen
31
32
#define pclose _pclose
@@ -79,33 +80,43 @@ Function: delete_directory
79
80
80
81
\*******************************************************************/
81
82
82
- void delete_directory (const std::string &path)
83
- {
84
- #ifdef _WIN32
85
-
86
- std::string pattern=path+" \\ *" ;
83
+ #ifdef _WIN32
87
84
85
+ void delete_directory_utf16 (const std::wstring &path)
86
+ {
87
+ std::wstring pattern=path + L" \\ *" ;
88
88
// NOLINTNEXTLINE(readability/identifiers)
89
- struct _finddata_t info;
90
-
91
- intptr_t handle=_findfirst (pattern.c_str (), &info);
92
-
93
- if (handle!=-1 )
89
+ struct _wfinddata_t info;
90
+ intptr_t hFile=_wfindfirst (pattern.c_str (), &info);
91
+ if (hFile!=-1 )
94
92
{
95
- unlink (info.name );
96
-
97
- while (_findnext (handle, &info)!=-1 )
98
- unlink (info.name );
93
+ do
94
+ {
95
+ if (wcscmp (info.name , L" ." )==0 || wcscmp (info.name , L" .." )==0 )
96
+ continue ;
97
+ std::wstring sub_path=path+L" \\ " +info.name ;
98
+ if (info.attrib & _A_SUBDIR)
99
+ delete_directory_utf16 (sub_path);
100
+ else
101
+ DeleteFileW (sub_path.c_str ());
102
+ }
103
+ while (_wfindnext (hFile, &info)==0 );
104
+ _findclose (hFile);
105
+ RemoveDirectoryW (path.c_str ());
99
106
}
107
+ }
100
108
101
- # else
109
+ # endif
102
110
111
+ void delete_directory (const std::string &path)
112
+ {
113
+ #ifdef _WIN32
114
+ delete_directory_utf16 (utf8_to_utf16_little_endian (path));
115
+ #else
103
116
DIR *dir=opendir (path.c_str ());
104
-
105
117
if (dir!=NULL )
106
118
{
107
119
struct dirent *ent;
108
-
109
120
while ((ent=readdir (dir))!=NULL )
110
121
{
111
122
std::string sub_path=path+" /" +ent->d_name ;
@@ -114,13 +125,10 @@ void delete_directory(const std::string &path)
114
125
else
115
126
remove (sub_path.c_str ());
116
127
}
117
-
118
128
closedir (dir);
119
129
}
120
-
121
- #endif
122
-
123
130
rmdir (path.c_str ());
131
+ #endif
124
132
}
125
133
126
134
/* ******************************************************************\
0 commit comments