I need to go through all the files of a specific folder (and its subfolders) and execute something in each file. I was looking for a way to recursively view all files and found one solution in Apache Commons Io: FileUtils.iterateFiles It returns an iterator. I checked how it is implemented and saw that it goes through all the files and adds them to the collection, and then returns an iterator for the collection. Well, of course, what is he doing. what i was looking for :)
But then I thought: is it efficient to collect all the files first, and then iterate over all of them and do what I want? Or should I, instead of collecting them, simply perform an action in a recursive traverse?
It should be noted that my required actions on files include I / O manipulations on them, which may not work .. (which can be processed in both directions .. but just noted if I missed something in my thoughts) Also , the set of folders and files that I’m browsing MAY reach 400 folders or 5000 files or so, and file sizes can reach several gigs (again, it’s not so important when just browsing files, but it’s relevant because I intend to complete the tasks input-output) ..
Any thoughts?
thanks.
source share