[Tutor] moving files from one dir to another

Dave Angel davea at ieee.org
Tue May 12 03:25:06 CEST 2009


Matt Herzog wrote:

> Should be simple, right? Not for me, heh.
>
> 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)
>
>
> The above code does not copy anything. I sure wish it would spit just one error.
>
> I sure wish I could for the last line go, 
>
> shutil.move("src", "dest")
>
> That would be cool.
>
> Plz halp!
>
>
>   
Just use os.rename()   if the dest is a directory, it'll move the file 
there.




More information about the Tutor mailing list