From 0d757ce36501f1aa1a7add8abb470b4055cf070b Mon Sep 17 00:00:00 2001 From: rasmusvt Date: Thu, 16 Jun 2022 16:26:41 +0200 Subject: [PATCH] Move get_filenames to auxillary and generalise --- nafuma/auxillary.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nafuma/auxillary.py b/nafuma/auxillary.py index 33a62fe..072ee83 100644 --- a/nafuma/auxillary.py +++ b/nafuma/auxillary.py @@ -1,5 +1,6 @@ import json import numpy as np +import os def update_options(options, required_options, default_options): ''' Takes a dictionary of options along with a list of required options and dictionary of default options, and sets all keyval-pairs of options that is not already defined to the default values''' @@ -71,4 +72,17 @@ def write_log(message, options={}): with open(options['logfile'], 'a') as f: - f.write(message) \ No newline at end of file + f.write(message) + + +#Function that "collects" all the files in a folder, only accepting .dat-files from xanes-measurements +def get_filenames(path, ext): + ''' Collects all filenames from specified path with a specificed extension + + Input: + path: path to find all filenames (relative or absolute) + ext: extension (including ".")''' + + filenames = [os.path.join(path, filename) for filename in os.listdir(path) if os.path.isfile(os.path.join(path, filename)) and filename.endswith(ext)] + + return filenames \ No newline at end of file