File tree Expand file tree Collapse file tree 1 file changed +24
-5
lines changed Expand file tree Collapse file tree 1 file changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -1387,12 +1387,31 @@ std::error_code remove_directories(const Twine &path, bool IgnoreErrors) {
1387
1387
Path16.push_back (0 );
1388
1388
Path16.push_back (0 );
1389
1389
1390
- SHFILEOPSTRUCTW shfos = {};
1391
- shfos.wFunc = FO_DELETE;
1392
- shfos.pFrom = Path16.data ();
1393
- shfos.fFlags = FOF_NO_UI;
1390
+ HRESULT HR = CoInitializeEx (NULL , COINIT_MULTITHREADED);
1391
+ if (SUCCEEDED (HR)) {
1392
+ IFileOperation *FileOp;
1393
+ HR = CoCreateInstance (CLSID_FileOperation, NULL , CLSCTX_ALL,
1394
+ IID_PPV_ARGS (&FileOp));
1395
+ if (SUCCEEDED (HR)) {
1396
+ HR = FileOp->SetOperationFlags (FOF_NO_UI | FOFX_NOCOPYHOOKS);
1397
+ if (SUCCEEDED (HR)) {
1398
+ IShellItem *ShItem = NULL ;
1399
+ HR = SHCreateItemFromParsingName (Path16.data (), NULL ,
1400
+ IID_PPV_ARGS (&ShItem));
1401
+ if (SUCCEEDED (HR)) {
1402
+ HR = FileOp->DeleteItem (ShItem, NULL );
1403
+ ShItem->Release ();
1404
+ }
1405
+ if (SUCCEEDED (HR)) {
1406
+ HR = FileOp->PerformOperations ();
1407
+ }
1408
+ }
1409
+ FileOp->Release ();
1410
+ }
1411
+ }
1412
+ CoUninitialize ();
1394
1413
1395
- int result = :: SHFileOperationW (&shfos) ;
1414
+ int result = FAILED (HR) ? HRESULT_CODE (HR) : 0 ;
1396
1415
if (result != 0 && !IgnoreErrors)
1397
1416
return mapWindowsError (result);
1398
1417
return std::error_code ();
You can’t perform that action at this time.
0 commit comments