Python script to find and copy files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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