问题描述
我想将程序的输出信息放置到一个文件夹中.如果给定的文件夹不存在,则程序应使用程序中给定的文件夹名称创建一个新文件夹.这可能吗?如果可以,请告诉我.
假设我给定了"C:\Program Files\alex"
之类的文件夹路径,并且alex
文件夹不存在,那么程序应该创建alex
文件夹,并将输出信息放置在alex
文件夹中.
您可以使用 os.makedirs()
并使用 os.path .exists()来查看它是否已经存在:
newpath = r'C:\Program Files\arbitrary'
if not os.path.exists(newpath):
os.makedirs(newpath)
如果您要制作安装程序: Windows Installer 为您做了很多工作. /p>
I want to put output information of my program to a folder. if given folder does not exist, then the program should create a new folder with folder name as given in the program. Is this possible? If yes, please let me know how.
Suppose I have given folder path like "C:\Program Files\alex"
and alex
folder doesn't exist then program should create alex
folder and should put output information in the alex
folder.
You can create a folder with os.makedirs()
and use os.path.exists() to see if it already exists:
newpath = r'C:\Program Files\arbitrary'
if not os.path.exists(newpath):
os.makedirs(newpath)
If you're trying to make an installer: Windows Installer does a lot of work for you.
这篇关于如何建立新资料夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!