gpt4 book ai didi

bash - 用 bash 读取子目录

转载 作者:行者123 更新时间:2023-12-02 17:47:13 25 4
gpt4 key购买 nike

我有一个文件夹,其中包含数百个带有图像的文件夹,每个文件夹中有 4 个随机名称的图像,我需要做的是遍历所有子文件夹,读取每个子文件夹的 4 个图像名称,然后对它们运行此命令:

 convert \( $subdir/$file1.jpg $subdir/$file2.jpg -append \) \( $subdir/$file3.jpg $subdir/$file4.jpg -append \) +append $subdir.jpg

它应该是这样工作的:

foreach(subdirectory in directory){
$img_arr[] = new Array();
foreach(file in subdirectory){
$img_arr[] = file;
}

exec("convert \( $subdirectory /$img_arr[0].jpg $subdirectory /$img_arr[1].jpg -append \) \( $subdirectory/$img_arr[2].jpg $subdirectory/$img_arr[3].jpg -append \) +append $subdirectory.jpg");
}

这是我到目前为止得到的:

#!/bin/bash

img=0;

IFS=$'\n'

for NAME in $(find -type f)
do
echo "Found a file: \"$NAME\""
done

我正在尝试使用 imagemagick 将 4 张图像合并为一张。谢谢!

最佳答案

试试这个:

for dir in *
do
test -d $dir || continue
files=($dir/*.jpg)
convert \( ${files[0]} ${files[1]} -append \) \( ${files[2]} ${files[3]} -append \) +append $dir.jpg
done

关于bash - 用 bash 读取子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13336580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com