Agree with Cornix - the second implementation is not only overly complicate, as posted it is incorrect (presuming I am understanding what the variable 'files' represents).