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

Method FileSetAttrib

source/script2.cpp:8477–8535  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8475};
8476
8477ResultType Line::FileSetAttrib(LPTSTR aAttributes, LPTSTR aFilePattern
8478 , FileLoopModeType aOperateOnFolders, bool aDoRecurse)
8479// Returns the number of files and folders that could not be changed due to an error.
8480{
8481 if (!*aFilePattern)
8482 return LineError(ERR_PARAM2_INVALID, FAIL_OR_OK);
8483
8484 // Convert the attribute string to three bit-masks: add, remove and toggle.
8485 FileSetAttribData attrib;
8486 DWORD mask;
8487 int op = 0;
8488 attrib.and_mask = 0xFFFFFFFF; // Set default: keep all bits.
8489 attrib.xor_mask = 0; // Set default: affect none.
8490 for (LPTSTR cp = aAttributes; *cp; ++cp)
8491 {
8492 switch (ctoupper(*cp))
8493 {
8494 case '+':
8495 case '-':
8496 case '^':
8497 op = *cp;
8498 case ' ':
8499 case '\t':
8500 continue;
8501 default:
8502 return LineError(ERR_PARAM1_INVALID, FAIL_OR_OK, cp);
8503 // Note that D (directory) and C (compressed) are currently not supported:
8504 case 'R': mask = FILE_ATTRIBUTE_READONLY; break;
8505 case 'A': mask = FILE_ATTRIBUTE_ARCHIVE; break;
8506 case 'S': mask = FILE_ATTRIBUTE_SYSTEM; break;
8507 case 'H': mask = FILE_ATTRIBUTE_HIDDEN; break;
8508 // N: Docs say it's valid only when used alone. But let the API handle it if this is not so.
8509 case 'N': mask = FILE_ATTRIBUTE_NORMAL; break;
8510 case 'O': mask = FILE_ATTRIBUTE_OFFLINE; break;
8511 case 'T': mask = FILE_ATTRIBUTE_TEMPORARY; break;
8512 }
8513 switch (op)
8514 {
8515 case '+':
8516 attrib.and_mask &= ~mask; // Reset bit to 0.
8517 attrib.xor_mask |= mask; // Set bit to 1.
8518 break;
8519 case '-':
8520 attrib.and_mask &= ~mask; // Reset bit to 0.
8521 attrib.xor_mask &= ~mask; // Override any prior + or ^.
8522 break;
8523 case '^':
8524 attrib.xor_mask ^= mask; // Toggle bit. ^= vs |= to invert any prior + or ^.
8525 // Leave and_mask as is, so any prior + or - will be inverted.
8526 break;
8527 default: // No +/-/^ specified, so overwrite attributes (equal and opposite to FileGetAttrib).
8528 attrib.and_mask = 0; // Reset all bits to 0.
8529 attrib.xor_mask |= mask; // Set bit to 1. |= to accumulate if multiple attributes are present.
8530 break;
8531 }
8532 }
8533 FilePatternApply(aFilePattern, aOperateOnFolders, aDoRecurse, FileSetAttribCallback, &attrib);
8534 return OK;

Callers

nothing calls this directly

Calls 1

ctoupperFunction · 0.85

Tested by

no test coverage detected