There's no need for `arrayOfPaths` and using 2 loops.  Just do this in a single loop when you iterate over the files in the dir.