This Flask application provides an API to recursively list files in a directory and retrieve the content of specific files. It includes two main routes: one for listing files and directories and another for fetching the content of a file.
- Recursively list files and directories starting from a root directory.
- Retrieve the content of a file through an API request.
- Python 3.x
- Flask
-
Clone the repository or download the files.
-
Make sure you have Flask installed. You can install it using pip:
pip install Flask
-
Run the Flask application:
python app.py
Lists all files and directories recursively starting from /home/ubuntu/
.
-
Success: Returns a list of dictionaries, each containing the
filetype
(eitherdir
orfile
) andpath
.Example:
[ {"filetype": "dir", "path": "/home/ubuntu/some_folder"}, {"filetype": "file", "path": "/home/ubuntu/some_folder/file.txt"} ]
Fetches the content of a specific file based on the provided file path.
- Content-Type:
application/json
- JSON Body:
{ "path": "/path/to/file" }
-
Success: Sends the file as a response for download.
-
Error: If the file path is a directory or the file path is invalid, it returns an error message.
Example error response:
{ "error": "filetype is directory" }
{ "error": "Invalid file Path" }
Once the server is running, you can use tools like curl
, Postman
, or any HTTP client to interact with the API:
curl http://localhost:4000/