python-3.x - Create folders as a function parameter in python
问题描述
In this code i am reading multiple folders and sent the files of each folder as input parameter to processing it in func2(), i need to save the output of processing in new creating folder how can i do that. my problem in this my code is just one folder is created and then the contents of the new folder passes again to func2()!
pp=1
directory = "out"+str(pp)
parent_dir = 'C:\\Users\\lap\\Desktop\\main\\enc\\'
path = os.path.join(parent_dir, directory )
os.mkdir(path)
print("Directory '% s' created" %directory)
input_path = Path(Path.home(), "Desktop", "main")
for root, dirs, files in os.walk(input_path):
for file in files:
file_path = Path(root, file)
#func(input files, output files)
cc = func(file_path,'C:\\Users\\lap\\Desktop\\main\\enc\\%s\\' %directory)
cc.func2()
pp+=1
解决方案
只创建一个文件夹的原因是,变量的值在循环directory
内永远不会改变。for
您可以在代码中添加这些行以获得您想要的内容。
...
for root, dirs, files in os.walk(input_path):
directory = "out"+str(pp)
for file in files:
...
推荐阅读
- css - 如何使用 CSS 将工具提示指针添加到 div
- html - 与 flex-direction 属性混淆
- python - Keras model.summary 函数显示不一致的输出格式
- c# - EF6 CurrentValues.SetValues 将当前值更改为 null
- powershell - 运行 ps 脚本的批处理文件
- javascript - 为什么当我点击提交时表单的参数消失了?
- java - 版本冲突,当前版本 [2] 与提供的版本 [1] 不同
- asp.net - 如何在其他函数上使用变量
- regex - 正则表达式:如何在某个字符之前的括号内获取所有内容?
- python-3.x - 仅从具有十六进制字符的字节编码 python 字符串中获取 ASCII 值