Skip to content

Instantly share code, notes, and snippets.

@rhcad
Created May 13, 2014 08:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rhcad/72ec9d14033813aaef04 to your computer and use it in GitHub Desktop.
Python script to find and copy files.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# sync.py: Find and copy files.
# Author: rhcad <github.com/rhcad>
import os, sys, shutil
def replacefiles(srcdir, dstdir, fn):
dstfile = os.path.join(dstdir, fn.lower())
if os.path.isfile(dstfile) and os.path.exists(dstfile):
os.remove(dstfile)
shutil.copy(os.path.join(srcdir, fn), os.path.join(dstdir, fn))
print(dstfile)
return
for fn2 in os.listdir(dstdir):
dstfile = os.path.join(dstdir, fn2)
if os.path.isdir(dstfile):
replacefiles(srcdir, dstfile, fn)
if __name__=="__main__":
srcdir = sys.argv[1]
dstdir = os.path.abspath('.')
for fn in os.listdir(srcdir):
replacefiles(srcdir, dstdir, fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment