Skip to content

Instantly share code, notes, and snippets.

@TimSC
Created March 31, 2017 21:21
Show Gist options
  • Select an option

  • Save TimSC/fb8657c0fc9c21b37d129d7c2f393bc3 to your computer and use it in GitHub Desktop.

Select an option

Save TimSC/fb8657c0fc9c21b37d129d7c2f393bc3 to your computer and use it in GitHub Desktop.
Extract every nth file
import sys
import os
import shutil
if __name__ == "__main__":
if len(sys.argv) < 4:
print ("Usage: {} src_folder dst_folder ith_frame".format(sys.argv[0]))
exit(0)
ithFrame = int(sys.argv[3])
if not os.path.exists(sys.argv[2]):
os.makedirs(sys.argv[2])
li = list(os.listdir(sys.argv[1]))
li.sort()
for fina in li[::ithFrame]:
shutil.copyfile(os.path.join(sys.argv[1], fina), os.path.join(sys.argv[2], fina))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment