如果用户输入不是目录,则如何使该目录成为默认值
让我们说用户输入是无效目录。如果是这样,我该如何使脚本自动将默认目录设置为本地文件或桌面?
Let us say a user input is an invalid directory. if so how can I make a script automatically set a default directory to a local file or the desktop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须使用
OS
库,并检查目录是否存在:如果
ISFILE
为false,则将其设置为您想要的任何默认目录。如果您希望将其设置为桌面,请使用:docs: https ://docs.python.org/3/library/os.html#os.environ
You have to use the
os
library and check if a directory exists:if
isFile
is false then set it to whatever default directory you want. If you want it to be set to Desktop, then use:docs: https://docs.python.org/3/library/os.html#os.environ
您可以使用
它是否存在。如果没有,则可以设置另一个
路径
。如果要更改目录,则可以使用
You can use
to see if it exists. If it does not, you can set set another
path
.If you want to change directory, you can use