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.

Python相关问答推荐

Geopandas未返回正确的缓冲区(单位:米)

BeautifulSoup:超过24个字符(从a到z)的迭代失败:降低了首次深入了解数据集的复杂性:

获取PANDA GROUP BY转换中的组的名称

如何将泛型类类型与函数返回类型结合使用?

如何将返回引用的函数与pybind11绑定?

多个矩阵的张量积

时间戳上的SOAP头签名无效

查找系统上安装的所有Python

try 第二次训练新的JAX+Equinox模型时,具有多个元素的数组的真值不明确(&Q)

更改Python中的数据格式

Chrome 122-如何允许不安全的内容?(不安全下载被阻止)

元组列表:如果第一个元组元素匹配,则合并两个数据帧列

如何在Ubuntu上更新ChromeDriver二进制文件

Python开发依赖项

向NumPy数组添加字符串

PANDA TO_DICT-按键列出行(_D)

从html获取元素时出现问题

如何生成一个区间的均匀分布的子区间?

在python的Pandas框架中完成两个条件时删除行

使用CSS Select 器和::before抓取不会显示文本