coping directories

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Feb 1 20:36:19 EST 2007


En Thu, 01 Feb 2007 21:33:03 -0300, Gigs_ <gigs at hi.t-com.hr> escribió:

> 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)

Instead of actually doing os.mkdir and cpfile, use a print statement to  
output the involved variables, and try with and without +1. You'll see  
yourself what happens.

-- 
Gabriel Genellina




More information about the Python-list mailing list