File size: 2,923 Bytes
e250d47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash

if [ -z "$BASH_VERSION" ]; then
    echo "This script requires Bash to run."
    exit 1
fi

image_ext=("jpg" "jpeg" "png" "bmp" "gif")

has_images() {
    local folder="$1"
    for ext in "${image_ext[@]}"; do
        shopt -s nullglob
        files=("$folder"/*."$ext")
        shopt -u nullglob
        if [ ${#files[@]} -gt 0 ]; then
            return 0
        fi
    done
    return 1
}

if [ ! -d "input" ]; then
    echo "The 'input' folder does not exist. Please run the folder creation script first."
    read -p "Press Enter to continue..."
    exit 1
fi

all_folders_have_images=true

for folder in input/*/; do
    if [ -d "$folder" ]; then
        if has_images "$folder"; then
            echo "The folder \"${folder}\" contains images."
        else
            echo "The folder \"${folder}\" does not contain any images."
            all_folders_have_images=false
        fi
    fi
done

if [ "$all_folders_have_images" = false ]; then
    echo
    echo "Please place at least one image in each folder. A minimum of 20 images per folder is recommended."
    read -p "Press Enter to continue..."
    exit 1
fi

if [ ! -d "output" ]; then
    mkdir "output"
    echo "'output' folder created."
else
    echo "The 'output' folder already exists."
fi

for folder in input/*/; do
    if [ -d "$folder" ]; then
        name=$(basename "$folder")
        output_path="output/$name"

        if [ ! -d "$output_path" ]; then
            mkdir "$output_path"
            echo "Folder '$output_path' created."
        else
            echo "Folder '$output_path' already exists."
        fi

        for sub in img log model; do
            subfolder="$output_path/$sub"
            if [ ! -d "$subfolder" ]; then
                mkdir "$subfolder"
                echo "Folder '$subfolder' created."
            else
                echo "Folder '$subfolder' already exists."
            fi
        done

        special_folder="$output_path/img/30_${name} person"
        if [ ! -d "$special_folder" ]; then
            mkdir "$special_folder"
            echo "Folder '$special_folder' created."
        else
            echo "Folder '$special_folder' already exists."
        fi
    fi
done

for folder in input/*/; do
    if [ -d "$folder" ]; then
        name=$(basename "$folder")
        source_folder="$folder"
        destination_folder="output/$name/img/30_${name} person"

        echo "Copying images from \"$source_folder\" to \"$destination_folder\"..."

        for ext in "${image_ext[@]}"; do
            shopt -s nullglob
            files=("$source_folder"/*."$ext")
            shopt -u nullglob
            if [ ${#files[@]} -gt 0 ]; then
                cp -u "${files[@]}" "$destination_folder"/
            fi
        done

        echo "Images copied for \"$name\"."
    fi
done

echo
echo "Folders created and images copied successfully!"
read -p "Press Enter to continue..."