使用shutil模块将文件移动到当前目录
我知道这可能听起来很愚蠢,但是如何将用户浏览到的目录(我命名为我的 filedir)中的文件移动到我所在的当前目录?
例如:我在“C:\webs”中有一个名为“pages.html”的文件。如何将该文件移动到当前工作目录“.”?
这是我的代码:
shutil.move(filedir, "*.*")
#I got errors using this code..
除了“.”之外,还有其他方式表示当前目录吗?
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 "." ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
shutil.move
的第二个参数指定目录,而不是全局掩码:应该可以。
The second argument of
shutil.move
specifies a directory, not a glob mask:should work.
如果您发布错误消息和完整的回溯,将会非常有帮助。但是,要获取当前工作目录,您可以使用
os.getcwd()
。只要filedir
指向一个文件而不是目录,这应该可以工作。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 asfiledir
points to a file and not the directory this should work.