• XSS.stack #1 – первый литературный журнал от юзеров форума

GO Lang Multi-Directory File Merger

DimmuBurgor

CPU register
Пользователь
Регистрация
01.12.2021
Сообщения
1 504
Решения
1
Реакции
552
Гарант сделки
6
This application allows the user to specify any two directory paths, and will merge any files that have the same filename.
Код:
package main

import (
    "fmt"
    "io/ioutil"
    "os"
    "path/filepath"
)

func main() {
    var dir1, dir2 string

    fmt.Print("Enter the first directory path: ")
    fmt.Scanln(&dir1)

    fmt.Print("Enter the second directory path: ")
    fmt.Scanln(&dir2)

    mergedDir := filepath.Join(dir1, "merged")
    err := os.MkdirAll(mergedDir, 0755)
    if err != nil {
        fmt.Printf("Error creating 'merged' directory: %v\n", err)
        return
    }

    files1, err := ioutil.ReadDir(dir1)
    if err != nil {
        fmt.Printf("Error reading directory %s: %v\n", dir1, err)
        return
    }

    files2, err := ioutil.ReadDir(dir2)
    if err != nil {
        fmt.Printf("Error reading directory %s: %v\n", dir2, err)
        return
    }

    filePaths := make(map[string][]string)

    for _, file := range files1 {
        if !file.IsDir() {
            fileName := file.Name()
            filePath := filepath.Join(dir1, fileName)
            filePaths[fileName] = append(filePaths[fileName], filePath)
        }
    }

    for _, file := range files2 {
        if !file.IsDir() {
            fileName := file.Name()
            filePath := filepath.Join(dir2, fileName)
            filePaths[fileName] = append(filePaths[fileName], filePath)
        }
    }

    for fileName, paths := range filePaths {
        mergedFilePath := filepath.Join(mergedDir, fileName)
        mergedContent := []byte{}

        for _, path := range paths {
            content, err := ioutil.ReadFile(path)
            if err != nil {
                fmt.Printf("Error reading file %s: %v\n", path, err)
                continue
            }
            mergedContent = append(mergedContent, content...)
        }

        err := ioutil.WriteFile(mergedFilePath, mergedContent, 0644)
        if err != nil {
            fmt.Printf("Error writing to file %s: %v\n", mergedFilePath, err)
        } else {
            fmt.Printf("Merged file %s saved\n", mergedFilePath)
        }
    }
}
 
Этот код очень общий, так где же здесь шифрование?
why should there be complex code when the task is simple? i think you may have confused the purpose of this utility.
 
Explain what the feature you want is in terms of Class, Functions and support needed and i'll adjust the logic so long as it does not turn in a massive project =)
 
**Vy more ne stolko soliy chto proizvesti tu eyforiya kotoraya nuzhna che ubedit menya snyatsyia vy okumental filme i prokommentirovat stroki dlya detsadovskogoshutit da drug?

how was my cipher?

There is not enough saltz in the sea to produce a strong enough euphoria that would convince me to document and comment the lines of a kindergarten code my friend



FUD = Fully UnDecipherable attempt to write RU without assistance =//
UPDATE: beyond embarassing =(
 
Последнее редактирование:
Может быть, моря и не такие соленые, как у вас, но язык хорошо справляется с задачей документирования флага. Вы только что использовали шифр cesear. То есть, https://pkg.go.dev/flag@go1.21.1
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх