[Tutor] copying files and regular expressions
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Mon May 1 21:07:34 CEST 2006
On Mon, 1 May 2006, Alfonso wrote:
> I'm totally new to python. I would like to know, how can I copy files
> using regular expressions (the equivalent in python to unix "cp
> /home/mycount/*partialname* /home/mycount/directory/").
Hi Alfonso,
Just as a pedantic note: the above pattern you're using isn't quite a
regular expression, but something less powerful called a "glob".
http://en.wikipedia.org/wiki/Glob
Knowing the common names of things matters sometimes just because we
communicate through the shared meanings of words. In this situation, it
does help because it turns out there's a 'glob' module in Python's
Standard Library:
http://www.python.org/doc/lib/module-glob.html
I'm not sure how familiar you are with using the Standard Library. Have
you used modules before?
The shell utilities defined in the 'shutil' module should also be helpful
to let you copy files from one path to another:
http://www.python.org/doc/lib/module-shutil.html
Best of wishes to you!
More information about the Tutor
mailing list