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 curren开发者_运维技巧t 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 "." ?
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.
It would be very helpful if you posted the error message and the complete traceback. However, to get the current working directory you can use os.getcwd()
. As long as filedir
points to a file and not the directory this should work.
filedir = r"C:\webs\pages.html"
shutil.move(filedir, os.getcwd())
精彩评论