On Wed, 2005-07-20 at 20:22 -0400, Bradford R. Bowman wrote:
> I know this should be easy, but how would I go about moving all files
> contained in one directory into another directory (as in the shell
> command "mv /path/to/dir1/* /path/to/dir2")?  Is the os module's rename
> function used for this?

I ended up with this function:

def movefiles(dir1, dir2):
  """Moves all files in dir1 to dir2"""
    contents = os.listdir(dir1)
    for file in contents:
      old = os.path.join(dir1, file)
      new = os.path.join(dir2, file)
      os.rename(old, new)
 
It seems to work, but this looks inelegant.  Does anyone have any better
suggestions?

-- 
Bradford R. Bowman
GnuPG Public Key available at:
http://mazirian.com/


Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to