It might be worth to consider using the Symfony's Filesystem component here (not in a scope of this PR).