On Tue, May 12, 2009 at 1:51 PM, Matt Herzog <[email protected]> wrote:
> On monday I posted the below code:
>
> def schmove(src,dst):
> ...         src = '/home/datasvcs/PIG/cjomeda_exp/'
> ...         dst = '/home/datasvcs/PIG/cjomeda_exp_archive/'
> ...         listOfFiles = os.listdir(src)
> ...         for filez in listOfFiles:
> ...             os.system("mv"+ " " + src + " " + dst)
>
> David Angel replied to my post and I guess I accidentally deleted his 
> response. Today I found his response posted on mail-archive.com and tried 
> some variations. They all failed.
>
> David said, "Just use os.rename() if the dest is a directory, it'll move the 
> file there."
>
> Example: If I use: "os.rename(src, dst)" where I had "os.system("mv"+ " " + 
> src + " " + dst)" no files are coppied.
>
> os.renames happily renames the source directory, but that's not what I want.

You are still not using the actual file name in your command. src is a
directory, so os.rename(src, dst) renames the directory. Try
os.rename(os.path.join(src, filez), os.path.join(dst, filez))

Kent
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to