0

I have a simple problem to which I don't find the answer on the net.

Like the title states it, I would like to go trough all the files in a directory AND his sub-directories. I know how to do it with find command but I would like to know how to do it with a simple for loop.

I initially have this line :

for file in $dir/*.png; do

And I'm sure there is a way to have some kind of $dir/*/*.png line that makes it possible with a for loop.

Thanks for your answers.

3
  • Hi, is there any specific reason to avoid using the find command? It makes life easier to use any decent tools available. Commented Dec 1, 2018 at 17:59
  • if only you could find an answer Commented Dec 1, 2018 at 17:59
  • 1
    just a for loop won't help you (you don't know levels of directory hierarchy). Without find tool, you may try to go with a recursive function Commented Dec 1, 2018 at 18:01

1 Answer 1

1

for file in $(find $dir - type f - name "*.png"); do

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I suppose there is no choice but to use that find command.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.