python get all json file paths in directory
- User
python get all json file paths in directory
Assistant
To get all JSON file paths in a directory using Python, you can use the
osorpathlibmodule. Below are examples of both approaches:Using
osModuleimport os import json def get_json_files(directory): json_files = [] for root, dirs, files in os.walk(directory): for file in files: if file.endswith('.json'): json_files.append(os.path.join(root, file)) return json_files # Example usage directory_path = '/path/to/your/directory' json_file_paths = get_json_files(directory_path) print(json_file_paths)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.