Rewrite in class, cleaner

This commit is contained in:
2024-08-08 08:09:16 -04:00
parent aea33d4fac
commit 52b44367c0
6 changed files with 156 additions and 107 deletions

23
file_type.py Normal file
View File

@@ -0,0 +1,23 @@
# file_type.py
# Identify type of file: file, directory, link, broken link
from pathlib import Path
class FileType():
@classmethod
def get_file_type(cls, filename):
# Return type of file ("file", "dir", "link", "broken-link", "other")
p = Path(filename)
if not p.exists():
if p.is_symlink():
return "broken-link"
else:
raise FileNotFound(errno.ENOENT, os.strerror(errno.ENOENT), filename)
if p.is_symlink():
return "symlink"
if p.is_dir():
return "directory"
elif p.is_file():
return "file"
return "other"