My guess is that it not only skips some
numbers, but that it deletes some files actually!
When renaming the files, you might end up
overwriting some already existing files. Take the
following example: You have 3 files: 0.jpg, 1.jpg,
2.jpg. They should be renamed as follows (a
possible result of your shuffling):
0.jpg -> 1.jpg
1.jpg -> 2.jpg
2.jpg -> 0.jpg
This would work if all the files would be
renamed at the same time. But if they are renamed
sequentually, the first renaming (
-> 1.jpg) will overwrite the "old"
1.jpg. When the "old"
1.jpg should be
renamed, it's actually the new
0.jpg) being renamed to
2.jpg, overwriting the "old"
2.jpg. And then, that file get's
renamed again to
So, you'll end up only with
(which in this case is actually the same as the
0.jpg), but you've
overwritten and thus lost the others.
Depending on your shuffling, you might end up
overwriting only some of the files, and thus see
some numbers skipped.
How to solve it? 2 Variants:
1) move the files to a new directory, and then in
the end delete the old directory (it should be
empty now, as all files have been moved) and
rename the new directory to the name of the
original directory. 2) rename the files first to
include some prefix, e.g.
"tmp_" + j + "." +
extension, and after all files have been
renamed, rename the files again to remove the
Both variants make sure that no file is