hi people I have problem with this example, not actually the problem, but [code] class FileVisitor(object): def __init__(self, data=None): self.context = data def run(self, startdir=os.curdir): os.path.walk(startdir, self.visitor, None) def visitor(self, data, dirname, filesindir): self.visitdir(dirname) for fname in filesindir: fpath = os.path.join(dirname, fname) if not os.path.isdir(fpath): self.visitfile(fpath) def visitdir(self, dirpath): # override or extend this method print dirpath, '...' def visitfile(self, filepath): # override or extend this method print self.fcount, '=>', filepath # class CVisitor(FileVisitor): def __init__(self, fromdir, todir): self.fromdirLen = len(fromdir) + 1 # here is my problem self.todir = todir FileVisitor.__init__(self, fromdir) def visitdir(self, dirpath): topath = os.path.join(self.todir, dirpath[self.fromdirLen:]) os.mkdir(topath) def visitfile(self, filepath): topath = os.path.join(self.todir, filepath[self.fromdirLen:]) cpfile(filepath, topath) #copy contents from filepath to topath[/code]
When I copy contents from C:\IronPython to C:\temp its all goes fine when self.fromdirLen = len(fromdir) + 1 is like this self.fromdirLen = len(fromdir) + 1 but when I change self.fromdirLen = len(fromdir) + 1 to self.fromdirLen = len(fromdir) i get contents copied to C:\ (actually to parent dir) Can anyone explain me that? Thanks!!! :o -- http://mail.python.org/mailman/listinfo/python-list