I am exporting an animation as PNG image files. From the 1199 sequences of frames exported, only every 4th file contains a key frame the rest of the image files are exact duplicates of the previous.

How can I copy only the 4th file into a New Folder?

file-20000.png - Copy
file-20001.png - Duplicate of file-20000
file-20002.png - Duplicate of file-20000
file-20003.png - Duplicate of file-20000
file-20004.png - Copy
file-20005.png - Duplicate of file-20004
file-20006.png - Duplicate of file-20004
file-20007.png - Duplicate of file-20004
file-20008.png - Copy

Use a FOR /L loop and set the start to 0, the step to 4 and the end to 1200 which is one more than the 1199 number sequences of file name parts which you need only to copy the fourth file.

This will iterate the numbers starting at 0 going from 0, 4, 8, .... 1196 counting by 4's and you can append the iterated value as a string concatenated within a portion of a file name along with a wildcard mask and use that with xcopy to copy each 4th file accordingly.

Batch Script

Note: This logic assumes the file names will always start with "file-2" and always end with the sequence numbers just before the dot before the extension png (i.e. <SeqNum>.png).


SET SrcDir=C:\folder\src
SET DestDir=C:\folder\dest
SET fNamePart=file-2
SET ext=png

FOR /L %%a IN (0, 4, 1200) DO (
    ECHO F | XCOPY /Y /F "%SrcDir%\%fNamePart%*%%a.%ext%" "%DestDir%\"


Further Resources

  • FOR /L

    FOR /L %variable IN (start,step,end) DO command [command-parameters]
        The set is a sequence of numbers from start to end, by step amount.
        So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
        generate the sequence (5 4 3 2 1)


If all the files that you want have Copy in their names, and all the files that you don’t want don’t have Copy in their names, then you can use *Copy*, as in

copy *Copy* DestinationDirectory
or use *copy*, since Windows is case insensitive.  If all the files that you want have Copy at the end of their names, you can use *Copy instead (leaving off the * at the end).  You can use filename patterns in Windows Explorer by typing file:*copy* into the search box.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.