file_name_in_folder.py
unknown
python
a year ago
654 B
3
Indexable
Never
import os import json def get_file_names(directory): files = [] for filename in os.listdir(directory): if os.path.isfile(os.path.join(directory, filename)): files.append(filename) return files def store_file_names(directory, json_file): files = get_file_names(directory) with open(json_file, 'w') as f: json.dump(files, f) # Get the current directory of the script script_directory = os.path.dirname(os.path.abspath(__file__)) # Create the JSON file path json_file_path = os.path.join(script_directory, 'output.json') # Store file names in JSON file store_file_names(script_directory, json_file_path)