so I'm working with a file directory for which I need to write a function that, when given arguments that lead to a folder in that directory, can extract metadata from the first and last file in that folder. I have written a function that extracts metadata when given a file path to a single file but I also need one that does this without the file being a specified endpoint.
Can anyone help me? I don't know how to get the function to go into the specified folder and read specific files without the files being arguments. Does that make sense? Sorry if it doesn't. Thanks.
答案 0 :(得分:0)
A bit sketchy (not a working code!) but I hope you get the idea
import os
def extract_metadata(file_path):
pass
def full_path(folder_path, fname):
return os.path.join(folder_path, fname)
def folder_metadata(folder_path):
file_names = os.listdirt(folder_path)
file1 = full_path(select_first(file_names))
file2 = full_path(select_last(file_names))
return extract_metadata(file1), extract_metadata(file2)