I
I
Ivan Korsakov2017-02-11 19:34:12
bash
Ivan Korsakov, 2017-02-11 19:34:12

How to carry out enumeration?

#!/bin/bash
echo "Start"
for file in `find test/*/*.png`
do
  convert $file $file.gif
done
echo "Finish"

Such a script does an action in each of the test subdirectory: it converts each png file into a new gif file. Is it possible to combine all the files in a subdirectory into one and move on to the next folder?
The output will be as many new files as there are folders, not as many old png files.
Thank you all and I apologize for the stupidity of the question)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2017-02-11
@shevchenkonik

$ find ./test -type f -name '*.png' -exec convert {} {}.gif \;

Do you need to concatenate files or what?
#!/bin/bash
set -e
for dirs in $(find ./test -type d -name 'images'); do
  for dir in "${dirs}"; do
    imgs=$(find "${dir}" -type f -name '*.jpg' -o -name '*.jpeg' -o -name '*.png')
    cat ${imgs} > "${dir}"/$$.gif;
  done
done

./test
├── 1
│   └── images
│       ├── 1.jpg
│       ├── 2.jpg
│       ├── 3.jpg
│       └── 4898.gif
├── 2
│   └── images
│       ├── 1.jpg
│       ├── 2.jpg
│       ├── 3.jpg
│       └── 4898.gif
├── 3
│   └── images
│       ├── 1.jpg
│       ├── 2.jpg
│       ├── 3.jpg
│       └── 4898.gif
└── images
    ├── 1.jpg
    ├── 2.jpg
    ├── 3.jpg
    └── 4898.gif

S
sim3x, 2017-02-11
@sim3x

How to reduce thousands of pictures in all subfolders?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question