import os
class FCopy(object):
def __init__(self, source):
self.source = source
self.target = os.path.join(source, '_output')
if not os.path.exists(self.target):
os.makedirs(os.path.abspath(self.target))
self.lf, self.ld = [], []
def walk(self, path):
for x in (os.path.join(path, x) for x in os.listdir(path)):
if x == self.target:continue
if os.path.isfile(x):
self.lf.append(x)
elif os.path.isdir(x):
self.ld.append(x)
self.walk(x)
#extra code if you want to handle symlinks
def do(self):
#if thats all you want,
#code this directly in walk
self.walk(self.source)
for x in self.ld:
x = x.replace(self.source, self.target)
os.makedirs(x)
for x in self.lf:
x = x.replace(self.source, self.target)
with open(x, 'w') as f:pass
f = FCopy('C:\\PerfLogs\\w\\tmp\\codemirror')
f.do()
You may play with ifexists and so on. If all you want is double the structure of source, then you could move the creation of files/dirs in walk, in corresponding if...else P.S.: ignore my dir, I just make a test in it