我有以下文件夹结构
foo/images
foo/infos
infos 包含一组 xml 文件,这些文件描述了 foo/images 文件夹中的图像。命名约定是以下用于图像的image1.png和用于描述符的image1.xml。我试图解决的问题如下:删除所有没有关联描述符的图像。
我一直在使用 emacs dired 为此很长一段时间取得了巨大的成功。但是,现在我需要在没有安装 emacs 的系统上执行此操作,bash 是唯一的选择。
#!/bin/bash
infosdir="foo/infos"
imagesdir="foo/images"
# use a different IFS to allow spaces in filenames
IFS=$(echo -en "\n\b")
# for all images in the images-directory
for pngfullname in ${imagesdir}/*.png; do
# get the name of the image without the path and without the file-extension
basename="$(basename ${pngfullname} .png)"
# if an appropriate xml-file in the infos-directory is missing
if [ ! -f "${infosdir}/${basename}.xml" ] ; then
# delete the image
rm "${pngfullname}"
fi
done
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句