Designing Table and Data For Folder Structure To Be Use On User Interface

I need to design a web page where it involve tree structure/ directory structure, each folder / file will be a record. So what will be the best way to query what I needed? Below have a solution which is quite useful.