Reputation: 349
I have files that have no extension but have the string "-DT-" in the filename, and other files that have the extension .fff. I want to process both types.
local dir imfiles
for imfiles in "$dir"**/*-DT-!(.jpg); do
printf "File processed: ${imfiles}\n"
done
The result would be the for-loop processing both types of files. I have tried using an array, but it didn't work. I have seen a lot of examples of for-loop but none approaching this specific scenario.
Upvotes: 1
Views: 53
Reputation: 241908
As the two groups don't overlap, you can specify one after the other:
for imfile in "$dir"/*-DT-!(*.*) "$dir"/*.fff ; do
Upvotes: 0
Reputation: 8104
Try
shopt -s dotglob extglob nullglob globstar
for imfiles in "$dir"**/@(*-DT-!(*.jpg)|*.fff); do
printf "File processed: ${imfiles}\n"
done
!(*.jpg)
and @(*-DT-!(*.jpg)|*.fff)
.Upvotes: 1
Reputation: 34514
One idea using find
to locate the desired files (assuming all files located under the same $dir
):
while read -r imfiles
do
printf "File processed: ${imfiles}\n"
done < <(find "${dir}" -name "*-DT-*" -o -name "*.fff" 2>/dev/null)
If the files are under different directories then chain 2 find
calls together, eg:
while read -r imfiles
do
printf "File processed: ${imfiles}\n"
done < <(find "${dir}" -name "*-DT-*" 2>/dev/null; find . -name "*.fff" 2>/dev/null)
NOTE: adjust the find
command as needed, eg, do not search in sub-directories, look for files of specific size, etc.
Upvotes: 0