[issue46791] Allow os.remove to defer to rmdir

benrg report at bugs.python.org
Mon Feb 28 14:59:50 EST 2022


benrg <benrudiak at gmail.com> added the comment:

The REMOVE_DIR case reduces to

    return RemoveDirectoryW(path->wide) ? 0 : -1;

so I think there's no reason to combine it with the other two.

The REMOVE_BOTH case is

    attrs = GetFileAttributesW(path->wide);

    if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) {
        success = RemoveDirectoryW(path->wide);
    } else {
        success = DeleteFileW(path->wide);
    }

    return success ? 0 : -1;

For REMOVE_BOTH, I don't see the need of calling GetFileAttributes - couldn't you just try DeleteFile, and if that fails, RemoveDirectory?

----------
nosy: +benrg

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46791>
_______________________________________


More information about the Python-bugs-list mailing list