Design and implement a virtual directory system that simulates a hierarchical file/folder structure using a single database table or collection — similar to a real filesystem — without interacting with the actual file system.
All operations must be performed via direct database queries (e.g., SQL, MongoDB , etc.), not through application-layer recursion.
You are required to build the following core operations:
Function | Description |
---|---|
create(name, type, parentId) |
Create a file or folder under the given parent. |
list(parentId) |
List immediate children (files + folders) under a parent. |
rename(id, newName) |
Rename the given file/folder. |
move(id, newParentId) |
Move the file/folder to a different directory. |
delete(id) |
Recursively delete the folder and all of its children using only SQL/DB query (no recursive logic in application code). |
You are free to design your own schema but ensure it supports:
'file'
or 'folder'