Asynchronous file search by pattern
C#
Medium
async
Task «Asynchronous file search by pattern»
Write an asynchronous program that takes a root directory and a file name pattern (with support for '*' and '?') as input. The program should asynchronously traverse all subdirectories recursively, find all files matching the pattern, and output their full paths. For each found file, it is also necessary to asynchronously read the first 1024 bytes and compute their SHA256 hash (as a hexadecimal string). The output should be sorted by file path. Constraints: the number of files does not exceed 1000, nesting depth up to 10, the file size can be arbitrary, but the first 1024 bytes are always read.
Input Format
First line: root directory (absolute or relative path). Second line: file name pattern (may contain '*' and '?').
Output Format
For each found file, output a line: "<full path> <SHA256 hash of the first 1024 bytes>". The lines are sorted by path in lexicographic order. If the file is empty, the hash is calculated from an empty string.
Examples
Example 1
INPUT
/tmp/testdir
file?.dat
OUTPUT
Example 2
INPUT
Programming is fun
OUTPUT
Example 3
INPUT
3
1 2 3
4 5 6
7 8 9
OUTPUT
Example 4
INPUT
hello world
world
java
OUTPUT
main.cs