Create folder structure similar to local folder structure using csv file

I have folders.csv file which incldues data of uploaded folders on servers we use doubly link list approach here so every folder has parent and child parent mean previous folder and child mean forward folder and if parent id is NULL it means it is root folder i am trying to create a structure similar to how i have folder structure locally what i need to do is get those folders from local directory which are not in csv file for a specific root folder
Below is my code attached

> import csv
> def build_folder_tree(csv_file):
>     folder_tree = {}
>     with open(csv_file, 'r',encoding="utf-8") as file:
>         reader = csv.DictReader(file)
>         for row in reader:
>             parent_id = row['parent_id']
>             folder_id = row['id']
>             folder_name = row['name']
>             if parent_id == 'NULL':
>                 folder_tree[folder_id] = {'name': folder_name, 'children': []}
>             else:
>                 parent_folder = folder_tree.get(parent_id)
>                 if parent_folder:
>                     parent_folder['children'].append({'id': folder_id, 'name': folder_name, 'children': []})
>     return folder_tree
> csv_file = 'folders.csv'  # Replace with your CSV file path
> folders = build_folder_tree(csv_file)
> print(folders)

The csv file contains id of the folder ,name of folder and parent id which is NULL in case it is a root folder we need to use this csv file to create folder structure

Have you seen the pathlib module? pathlib — Object-oriented filesystem paths — Python 3.11.4 documentation

I think it will be very helpful for your task. It can traverse existing directories (Path.iterdir) and create new ones (Path.mkdir).