MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / Util_RemoveDir

Method Util_RemoveDir

source/script_autoit.cpp:1488–1528  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1486
1487
1488bool Line::Util_RemoveDir(LPCTSTR szInputSource, bool bRecurse)
1489{
1490 SHFILEOPSTRUCT FileOp;
1491 TCHAR szSource[_MAX_PATH+2];
1492
1493 // If recursion not on just try a standard delete on the directory (the SHFile function WILL
1494 // delete a directory even if not empty no matter what flags you give it...)
1495 if (bRecurse == false)
1496 {
1497 // v1.1.31.00: Use the original source path in case its length exceeds _MAX_PATH.
1498 // Relative paths and trailing slashes are okay in this case, and Util_IsDir() is
1499 // not needed since the function only removes empty directories, not files.
1500 if (!RemoveDirectory(szInputSource))
1501 return false;
1502 else
1503 return true;
1504 }
1505
1506 // Get the fullpathnames and strip trailing \s
1507 Util_GetFullPathName(szInputSource, szSource);
1508
1509 // Ensure source is a directory
1510 if (Util_IsDir(szSource) == false)
1511 return false; // Nope
1512
1513 // We must also make double nulled strings for the SHFileOp API
1514 szSource[_tcslen(szSource)+1] = '\0';
1515
1516 // Setup the struct
1517 FileOp.pFrom = szSource;
1518 FileOp.pTo = NULL;
1519 FileOp.hNameMappings = NULL;
1520 FileOp.lpszProgressTitle = NULL;
1521 FileOp.fAnyOperationsAborted = FALSE;
1522 FileOp.hwnd = NULL;
1523
1524 FileOp.wFunc = FO_DELETE;
1525 FileOp.fFlags = FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION | FOF_NOERRORUI;
1526
1527 return !SHFileOperation(&FileOp);
1528}
1529
1530
1531

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected