I\'m writing a bash script that needs to loop files inside a directory that do not match a specific extension. So far, I\'ve found that the following code loops all files th
to loop files inside a directory that do not match a specific extension
You can use extglob
:
shopt -s extglob
for f in *.!(txt); do
echo "$f"
done
pattern *.!(txt)
will match all entries with a dot and no txt
after the dot.
EDIT: Please see comments below. Here is a find
version to loop through files in current directory that don't match a particular extension:
while IFS= read -d '' -r f; do
echo "$f"
done < <(find . -maxdepth 1 -type f -not -name '*.txt' -print0)