24 lines
661 B
Python
24 lines
661 B
Python
# 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"
|