You should simply use a loop - either a for , while, or until loop should work fine. You would possibly need a counter which you can set up easily (set counter = 1 or 0 , increment it on each pass through the loop, stop the loop when the counter is equal or greater than the number of files)