#K51717. Recursive File Listing
Recursive File Listing
Recursive File Listing
You are given a simulated file system with a fixed structure. The file system is defined as follows:
[ \begin{aligned} &/ \quad : \quad { "folder1/", "file4.txt" }\[5pt] &/folder1/ \quad : \quad { "file1.txt", "folder2/", "folder3/" }\[5pt] &/folder1/folder2/ \quad : \quad { "file2.txt" }\[5pt] &/folder1/folder3/ \quad : \quad { "file3.txt" } \end{aligned} ]
Additionally, a helper function distinguishes between files and directories: a path ending with a slash represents a directory, and paths not ending with a slash represent files. Your task is to implement a program that reads a single absolute path from standard input and recursively lists all files contained in that path. If the given path is a file, simply output the file path. If the path does not exist in the file system, output nothing. The output must be sorted in lexicographical order with one file path per line.
For example, if the input is "/folder1/", the correct output is:
/folder1/file1.txt /folder1/folder2/file2.txt /folder1/folder3/file3.txt
inputFormat
The input consists of a single line containing an absolute path (a string). This path may represent either a file or a directory in the simulated file system.
outputFormat
Output all the file paths found by recursively exploring the given path. If the input path is a file, output that file path. If it doesn't exist or contains no files, output nothing. Each file path should be printed on a separate line in lexicographical order.## sample
/
/file4.txt
/folder1/file1.txt
/folder1/folder2/file2.txt
/folder1/folder3/file3.txt
</p>