@@ -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,42 +80,55 @@ 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
- remove ((path+" /" +ent->d_name ).c_str ());
111
-
121
+ {
122
+ std::string sub_path=path+" /" +ent->d_name ;
123
+ if (ent->d_type ==DT_DIR)
124
+ delete_directory (sub_path);
125
+ else
126
+ remove (sub_path.c_str ());
127
+ }
112
128
closedir (dir);
113
129
}
114
-
115
- #endif
116
-
117
130
rmdir (path.c_str ());
131
+ #endif
118
132
}
119
133
120
134
/* ******************************************************************\
0 commit comments