e vtyz tcnm ghjuhfvvf jgbib gjlhj,yj rfr t` pfgecnbnm gjifujdj 
package FolderScanner;

import java.io.*;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.*;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class FolderScanner {

    static class FileInformation {
        String type;
        long size;
        String modt;
        String hash;

        FileInformation(String type, long size, String modt, String hash) {
            this.type = type;
            this.size = size;
            this.modt = modt;
            this.hash = hash;
        }
    }

    static class DirectoryInformation {
        String type;
        Map<String, Object> entries;

        DirectoryInformation(String type, Map<String, Object> entries) {
            this.type = type;
            this.entries = entries;
        }
    }

    static class ScanInformation {
        String path;
        String startDate;
        String finishDate;
        Object scan;
        String hash;

        ScanInformation(String path, String startDate, String finishDate, Object scan, String hash) {
            this.path = path;
            this.startDate = startDate;
            this.finishDate = finishDate;
            this.scan = scan;
            this.hash = hash;
        }
    }

    public static void main(String[] args) {
        if (args.length == 0) {
            System.err.println("Помощь: [-h alg] path\n"
                    + "-h alg - алгоритм хэширования (md5, sha256, sha512, gost256, gost512)\n"
                    + "path - путь к папке или файлу для сканирования.");
            return;
        }

        String path = args[args.length - 1];
        String hashAlgorithm = null;

        if (args.length > 1 && args[0].equals("-h")) {
            hashAlgorithm = args[1];
            if (!Arrays.asList("md5", "sha256", "sha512", "gost256", "gost512").contains(hashAlgorithm)) {
                System.err.println("Неизвестный алгоритм хэширования: " + args[1]);
                return;
            }
        }

        try {
            Path folderPath = Paths.get(path);
            if (!Files.exists(folderPath)) {
                System.err.println("Путь не существует: " + path);
                return;
            }

            Map<String, Object> entries = new HashMap<>();
            String startDate = getCurrentDate();
            scanFolder(folderPath, entries, hashAlgorithm);
            String finishDate = getCurrentDate();

            String hash = hashAlgorithm != null ? hashAlgorithm : null;
            ScanInformation scanInfo = new ScanInformation(path, startDate, finishDate, entries, hash);
            
            Gson gson = new GsonBuilder().setPrettyPrinting().create();
            String jsonOutput = gson.toJson(scanInfo);
            System.out.println(jsonOutput);

            try (BufferedWriter writer = Files.newBufferedWriter(Paths.get("scan_result.json"))) {
                writer.write(jsonOutput);
            }

        } catch (IOException e) {
            System.err.println("Ошибка: " + e.getMessage());
        } catch (Exception e) {
            System.err.println("Ошибка: " + e.getMessage());
        }
    }

    private static void scanFolder(Path folder, Map<String, Object> entries, String hashAlgorithm) throws Exception {
        BasicFileAttributes attr = Files.readAttributes(folder, BasicFileAttributes.class);
        if (attr.isDirectory()) {
            entries.put(folder.getFileName().toString(), new DirectoryInformation("dir", new HashMap<>()));
            Map<String, Object> dirEntries = ((DirectoryInformation) entries.get(folder.getFileName().toString())).entries;
            
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(folder)) {
                for (Path entry : stream) {
                    if (Files.isDirectory(entry)) {
                        scanFolder(entry, dirEntries, hashAlgorithm);
                    } else if (Files.isRegularFile(entry)) {
                        String hash = (hashAlgorithm != null) ? calculateHash(entry, hashAlgorithm) : null;
                        dirEntries.put(entry.getFileName().toString(), new FileInformation("file", Files.size(entry), getModificationDate(entry), hash));
                    }
                }
            }
        } else {
            String hash = (hashAlgorithm != null) ? calculateHash(folder, hashAlgorithm) : null;
            entries.put(folder.getFileName().toString(), new FileInformation("file", Files.size(folder), getModificationDate(folder), hash));
        }
    }

    private static String calculateHash(Path file, String algorithm) throws Exception {
        MessageDigest digest = MessageDigest.getInstance(algorithm);
        try (InputStream is = Files.newInputStream(file)) {
            byte[] buffer = new byte[8192];
            int bytesRead;
            while ((bytesRead = is.read(buffer)) != -1) {
                digest.update(buffer, 0, bytesRead);
            }
        }
        StringBuilder hexString = new StringBuilder();
        for (byte b : digest.digest()) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1) hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString();
    }

    private static String getModificationDate(Path file) throws IOException {
        BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(attrs.lastModifiedTime().toMillis()));
    }

    private static String getCurrentDate() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }
}