import os

target_folder = "123" search_folder = "12" new_folder = "1"

for root, dirs, files in os.walk(target_folder): if search_folder in dirs: path = os.path.join(root, search_folder) new_path = os.path.join(path, new_folder) try: os.mkdir(new_path) print(f"Created folder {new_folder} in {path}") except FileExistsError: print(f"Folder {new_folder} already exists in {path}")

利用以上代码帮我写个查找123路径下名为12的文件夹并在该文件夹内创建一个名为1的文件夹

原文地址: http://www.cveoy.top/t/topic/bytW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录