-
-
Save rand-tech/0385e35a5d4bf342ea7e5ad9c0edefc0 to your computer and use it in GitHub Desktop.
Readable file flag reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Check file flags of a given file. | |
''' | |
import os | |
import stat | |
import argparse | |
def get_file_flags(filepath): | |
try: | |
st = os.stat(filepath) | |
except FileNotFoundError: | |
return f"File not found: {filepath}" | |
flags = { | |
"UF_NODUMP": stat.UF_NODUMP, | |
"UF_IMMUTABLE": stat.UF_IMMUTABLE, | |
"UF_APPEND": stat.UF_APPEND, | |
"UF_HIDDEN": stat.UF_HIDDEN, | |
"SF_ARCHIVED": stat.SF_ARCHIVED, | |
"SF_IMMUTABLE": stat.SF_IMMUTABLE, | |
"SF_APPEND": stat.SF_APPEND, | |
} | |
set_flags = [flag for flag, value in flags.items() if st.st_flags & value] | |
return set_flags | |
def main(): | |
parser = argparse.ArgumentParser(description=__doc__) | |
parser.add_argument("filepath", type=str) | |
args = parser.parse_args() | |
filepath = args.filepath | |
file_flags = get_file_flags(filepath) | |
print(f"{filepath}:\t", ", ".join(file_flags)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment