It'll be better to store folder structure in a single table, rather creating a table for each folder.
For example, such table could have structure like:
╔═══════════╦══════╦══════════════════════════════════╗
║ Column ║ Type ║ Description ║
╠═══════════╬══════╬══════════════════════════════════╣
║ id ║ int ║ Unique identifier of the folder ║
║ parent_id ║ int ║ id of the parent folder ║
║ name ║ text ║ Name of the folder ║
║ mpath ║ text ║ Materialized path of parent id's ║
╚═══════════╩══════╩══════════════════════════════════╝
Note about materialized path: it is optional, and could be added to make it faster to run queries like "Get all children of folder 123" without recusive calls.
So, let's pretend you have this folder structure:
/
├── home/
│ ├── aspiring-master
│ │ └── .bashrc
│ └── guest-user
└── var/
├── log/
└── lib/
It could be presented in form of mentioned table like this:
╔════╦═══════════╦═══════════════════╦═══════════╗
║ id ║ parent_id ║ name ║ mpath ║
╠════╬═══════════╬═══════════════════╬═══════════╣
║ 1 ║ null ║ "/" ║ "/" ║
║ 2 ║ 1 ║ "home" ║ "/1/" ║
║ 3 ║ 2 ║ "aspiring-master" ║ "/1/2/" ║
║ 4 ║ 3 ║ ".bashrc" ║ "/1/2/3/" ║
║ 5 ║ 2 ║ "guest-user" ║ "/1/2/" ║
║ 6 ║ 1 ║ "var" ║ "/1/" ║
║ 7 ║ 6 ║ "log" ║ "/1/6/" ║
║ 8 ║ 6 ║ "lib" ║ "/1/6/" ║
╚════╩═══════════╩═══════════════════╩═══════════╝
In python you can use some ORM, such as sqlAlchemy, and, in that case, your folder would be represented as a class, implementing Model:
class Folder(db.Model):
id = db.Column(db.Integer, primary_key=True)
parent_id = db.Column(db.Integer, db.ForeignKey('folder.id'),
nullable=True)
name = db.Column(db.String(128), unique=True, nullable=False)
mpath = db.Column(db.String(255), unique=True, nullable=False)
Functionality to automatically create mpath value also could be placed in this class.