python 中的文件夹操作
我的 xpto 文件夹中有许多名为 0、0.05、0.1、0.2、folder1、folder2 的文件夹。 我只想获取以数字命名的文件夹(它们始终在 0 和 2 之间)并移动到另一个文件夹。 所以,我想知道我需要移动哪些文件夹并且我正在尝试打印它们。该代码没有回答任何问题!
import os
import shutil
import numpy as np
pasta="xpto"
lista=[]
lst=np.arange(0.05,1,0.05).round(2)
for i in lst:
lista.append(i)
for foldername in os.listdir(os.path.join(xpto)):
if foldername in lista:
print(foldername)
I have many folders named as 0, 0.05, 0.1, 0.2, folder1, folder2 inside my xpto folder.
I want to get only the folders named with numbers (they are always between 0 and 2) and move to another folder.
So, I want to know what folders I need to move and I'm trying to print them. The code doesn't answer anything!
import os
import shutil
import numpy as np
pasta="xpto"
lista=[]
lst=np.arange(0.05,1,0.05).round(2)
for i in lst:
lista.append(i)
for foldername in os.listdir(os.path.join(xpto)):
if foldername in lista:
print(foldername)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道为什么你使用 numpy 来进行基本数学和目录代码,但基本上你只想迭代你的 listdir 并检查你想要的名称:
I don't know why you're using numpy for basic math and directory code, but basically you just want to iterate over your listdir and check the name anyway you want: