diff --git a/sites/cheerpx/src/assets/index_list_example.png b/sites/cheerpx/src/assets/index_list_example.png deleted file mode 100644 index 0303bd12..00000000 Binary files a/sites/cheerpx/src/assets/index_list_example.png and /dev/null differ diff --git a/sites/cheerpx/src/content/docs/11-guides/File-System-support.md b/sites/cheerpx/src/content/docs/11-guides/File-System-support.md index a8aca8a8..655a636c 100644 --- a/sites/cheerpx/src/content/docs/11-guides/File-System-support.md +++ b/sites/cheerpx/src/content/docs/11-guides/File-System-support.md @@ -32,11 +32,37 @@ const cx = await CheerpX.Linux.create({ }); ``` -This mounts the specified local directory at `/web` in the CheerpX filesystem. +This will mount the specified directory at `/web` in the CheerpX filesystem. To enable listing the directory contents, CheerpX looks for an `index.list` file in the directory and any subdirectories. This file should contain a newline-separated list of all files and subdirectories within the directory. -To be able to list the files, CheerpX will look for a file called index.list in the directory and each of its subdirectories. The file should contain a newline separated list of all files and folders contained in the directory. +### Why use an `index.list` File? -For detailed information about the purpose and usage of index.list, refer to the [index.list](/docs/reference/index.list) reference. +The `index.list` file enables CheerpX to provide directory listing functionality in its WebDevice. It ensures seamless navigation of directories, compatibility with Linux-based tools, and support for navigating directories operations like `os.listdir()`. Since browsers restrict direct access to local files, `index.list` helps simulate a directory structure for virtual environments, making it essential for managing and accessing files effectively. + +### Creating an `index.list` File + +To generate an `index.list` in every directory without including it in the directory listing, use the following command: + +```bash +find . -type d -exec sh -c 'cd "{}" && ls > .index.list && mv .index.list index.list' \; +``` + +**Explanation**: + +1. `find . -type d`: This part of the command finds all directories (`-type d`) starting from the current directory (`.`). + +2. `exec`: The `-exec` option runs the provided command for each directory found by `find`. + +3. `sh -c 'cd "{}" && ls > .index.list && mv .index.list index.list'`: + +- `sh -c`: Runs the following string as a shell command. +- `cd "{}"`: Changes the current directory to the directory being processed ({} is replaced with the directory path by find). +- `ls > .index.list`: Lists all files and directories in the current directory and writes the output to a temporary file named .index.list. +- `mv .index.list index.list`: Renames .index.list to index.list. + +4. `\;`: This marks the end of the -exec command for find. + +> [!warning] Warning +> Be careful when using this command. It will overwrite existing index.list files in every directory it processes. Ensure you run it only in the intended directory and back up any important data before execution. Misuse in the wrong directory could cause unintentional data loss. ### Accessing Files diff --git a/sites/cheerpx/src/content/docs/12-reference/21-index.list.md b/sites/cheerpx/src/content/docs/12-reference/21-index.list.md deleted file mode 100644 index e5c17ecd..00000000 --- a/sites/cheerpx/src/content/docs/12-reference/21-index.list.md +++ /dev/null @@ -1,136 +0,0 @@ ---- -title: Index.list -description: Purpose and usage of index.list ---- - -## What is `index.list` - -The index.list file serves as a directory index for a WebDevice in CheerpX. It lists all files and subdirectories within the directory where it resides. - -## Purpose of index.list - -The primary purpose of index.list are: - -- To enable the use of functions like os.listdir() to list directory contents. -- To provide seamless navigation of nested directories and files in the WebDevice. -- To ensure that CheerpX can recognize and display file structures for applications running in the virtual Linux environment. - -## Structure of `index.list` - -The `index.list` file contains a newline-separated list of all files and directories in the current directory. - -### Example directory structure - -Assume the directory structure is as follows: - -```bash -. -├── cheerpXImage.ext2 -├── Dockerfile -├── index.html -├── index.list.py -├── nginx.conf -└── web_root - ├── index.list - ├── main.py - ├── script1.py - └── scripts - ├── index.list - └── script2.py -``` - -**Content of** `/web_root/index.list`: - -``` -main.py -script1.py -scripts -``` - -**Content of** `/web/scripts/index.list`: - -``` -script2.py -``` - -## How to Use index.list - -1. Creating `index.list` files - -To generate `index.list` files, use the `index.list.py` script that goes over the given directory structure and creates `index.list` files where needed. - -```bash -python3 index.list.py -``` - -> [!note] Note -> You need to create the `web_root` directory to use this script effectively. - -2. Accessing Files in CheerpX - -Once `index.list` files are created, you can access and interact with the files and directories through CheerpX using Python. - -### Example code: - -```py -import os - -# List contents of the root directory in WebDevice -print(os.listdir('/web')) -# Output: ['main.py', 'data.txt', 'scripts'] - -``` - -3. Integrating with Your HTML - -The following index.html file, when served by an NGINX server configured with nginx.conf, will allow you to interact with the Python REPL through a browser: - -```html - - -
- -