#C127. Recursive File Listing in Nested Directory Structure
Recursive File Listing in Nested Directory Structure
Recursive File Listing in Nested Directory Structure
You are given a nested directory structure represented as a JSON object. In this structure, each directory is represented as an object where keys represent either subdirectories or file names. A file is represented by a key whose value is a string (the file contents), while a subdirectory is represented by a key whose value is another JSON object.
The task is to implement a function list_files
that accepts a path
(a string with directories separated by '/') and the directory structure
(given as a JSON object). The function should return a list of all file names (keys corresponding to files) located at the specified directory and all its subdirectories. If the given path does not exist in the structure, return an empty list.
All formulas, if any, must be rendered in LaTeX format. For example, if you need to reference the depth of recursion, you can denote it by \(d\). The order of the files should follow the order of key iteration in the provided JSON structure.
inputFormat
The input is read from stdin
and consists of two parts:
- The first line contains the
path
string. - The remaining lines form a valid JSON string representing the nested directory structure. You should parse this JSON to obtain the structure.
outputFormat
Print the file names, each on a separate line, to stdout
in the order they are found.
documents/projects/python
{"documents": {"projects": {"python": {"file1.py": "print('Hello World')", "file2.py": "print('Python is awesome!')"}, "javascript": {"file1.js": "console.log('Hello World')"}}, "notes": {"file1.txt": "Meeting notes", "file2.txt": "To-do list"}}, "music": {"rock": {"song1.mp3": "Song Data 1", "song2.mp3": "Song Data 2"}, "pop": {"song1.mp3": "Song Data 3"}}}
file1.py
file2.py
</p>