move a file to the current directory using shutil module

user715578 picture user715578 · Oct 11, 2011 · Viewed 8.6k times · Source

I know this may sound really stupid, but how can I move a file in a directory a user browsed to ( I named mine filedir) to the current directory I am in?

for example: I have a file called "pages.html" in "C:\webs". How can I move that file to the current working directory "."?

This is my code:

shutil.move(filedir, "*.*")
#I got errors using this code.. 

Is there another way to say current directory, other than "." ?

Answer

phihag picture phihag · Oct 11, 2011

The second argument of shutil.move specifies a directory, not a glob mask:

import os.path
shutil.move(os.path.join(filedir, "pages.html"), os.getcwd())

should work.