import os
import json

def get_files_in_folders(directory):
    folder_dict = {}
    
    # Walk through the directory recursively
    for root, dirs, files in os.walk(directory):
        folder_name = os.path.basename(root)  # Get folder name
        folder_dict[folder_name] = files  # Add files to the dict
    
    return folder_dict

def save_to_json(data, json_file):
    with open(json_file, 'w') as f:
        json.dump(data, f, indent=4)

if __name__ == "__main__":
    directory_to_scan = "REPORTS"  # Change this to your directory path
    json_output_file = "folders_and_files.json"  # Output JSON file

    # Get folder and file information
    folders_and_files = get_files_in_folders(directory_to_scan)

    # Save to JSON
    save_to_json(folders_and_files, json_output_file)

    print(f"JSON file saved as {json_output_file}")

