You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB
Python

import os
class FileReader:
def __init__(self, root: str):
if not os.path.isdir(root):
raise Exception("Root was not a valid directory! {0}".format(root))
self.__root = root
def list_artists(self) -> list:
"""
List all Artists within the root folder
:return:
"""
l = [os.path.basename(x) for x in os.listdir(self.__root)]
if ".artnet" in l:
l.remove(".artnet")
return l
def get_files(self, artist: str) -> list:
"""
List all files within the given artists directory with their relative path (to the root).
:param artist:
:return:
"""
l = []
root = os.path.join(self.__root)
dirs = [artist]
while len(dirs) != 0:
curr_dir = dirs.pop()
curr_full_dir = os.path.join(root, curr_dir)
l += [os.path.join(curr_dir, f) for f in os.listdir(curr_full_dir) if os.path.isfile(os.path.join(curr_full_dir, f))]
for d in [x for x in os.listdir(curr_full_dir) if os.path.isdir(os.path.join(curr_full_dir, x))]:
dirs.append(os.path.join(curr_dir, d))
return l
if __name__ == "__main__":
fr = FileReader("/home/peery/Software_Projects/ArtNet/App/Fake_Other_Artists")
print(fr.list_artists())
print(fr.get_files("AkuDrache"))