| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import os
- from .PathObject import PathObject
- from .FileObject import FileObject
- filetype = {
- "txt": "Text",
- "doc": "Text",
- "rtf": "Text",
- "odt": "Text",
- "mp3": "Music",
- "flac": "Music",
- "wav": "Music",
- "mp4": "Video",
- "flv": "Video",
- "mkv": "Video",
- "avi": "Video",
- "webm": "Video",
- "mov": "Video",
- "jpg": "Image",
- "jpeg": "Image",
- "png": "Image",
- "gif": "Image",
- "bmp": "Image",
- "tiff": "Image",
- "webp": "Image",
- "exe": "Executable"
- }
- # determines a file's type, based on its extension
- def determine_type(file_name):
- try:
- extension = str(file_name).rsplit('.', 1)[1]
- type = filetype.get(extension, "File")
- return type
- except:
- return "File"
- # creates two FileObject lists, containing all the files and
- # folders found in the path given as argument
- def get_files_dirs(path):
- dir_path = str(path)
- # lists for storing files and folders as FileObjects
- files = []
- dirs = []
-
- # inserts all file and folder names (strings) found in the path into file_names
- file_names = os.listdir(dir_path)
- for file in file_names:
- abs_path = os.path.join(dir_path, file)
- if os.path.isfile(abs_path):
- files.append(file)
- elif os.path.isdir(abs_path):
- dirs.append(file)
- return files, dirs
|