[Tutor] shutil question? on copying files

Scott Ralph Comboni scott@zenplex.com
05 Apr 2001 15:09:49 -0400


> On 05 Apr 2001 20:32:54 +0200, Remco Gerlich wrote:
> On  0, Scott Ralph Comboni <scott@zenplex.com> wrote:
> > I have a question in regards to the shutil module.  I'm trying to copy
> > via a wildcard shutil.copy('/project/tambora/packages/*tar*', '/tmp')
> > and I get this.
> > 
> >  File "<stdin>", line 1, in ?
> >   File "/usr/local/lib/python2.0/shutil.py", line 26, in copyfile
> >     fsrc = open(src, 'rb')
> > IOError: [Errno 2] No such file or directory:
> > '/projects/tambora/packages/*tar*'
> > 
> > It works fine if I put the complete path name in but I'd like to be able
> > to wildcard this. IS there a way to do this or another module to use? I
> > need to preform this function on *NIX and NT.
> 
> shutil does not do wildcars, but for that there is glob; try
> 
> import shutil, glob
> 
> for file in glob.glob('/projects/tambora/packages/*tar*'):
>    shutil.copy(file, '/tmp')
> 
> -- 
> Remco Gerlich
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
Thanks that solved my problem.  I should have thought of that still a
little green.
Scott

-- 
Scott Ralph Comboni
http://www.zenplex.com
http://www.zenplex.org
http://tambora.zenplex.org