gpt4 book ai didi

python - 从函数返回所有路径值

转载 作者:太空宇宙 更新时间:2023-11-03 21:08:39 25 4
gpt4 key购买 nike

我想知道如何通过 Return 检索循环的所有值。在我的第一个函数中,我循环恢复所有文件夹、子文件夹。然后我回到pathFiles

在我的第二个函数中,我在文件夹中的所有文件上测试我的 linux 命令,但问题是:我的函数仅测试循环的最后结果而不是所有值。

from ftplib import FTP
import ftplib
import os
import errno
import time

class ProcessFile:
path= "FolderFiles"
target=" /var/www/folder/Output"
extract=""
monitoring=""
bash="unrar "

@staticmethod
def returnPath():
pathFiles= []
for root, dirs, files in os.walk(ProcessFile.path, topdown=True):
for name in dirs:
os.path.join(root, name)
for name in files:
pathFiles= os.path.join(root, name)
print(pathFiles)
return pathFiles

@staticmethod
def testArchive(pathFile):
monitoring = ProcessFile.bash+"t "+pathFile
verifyFiles = os.system(monitoring)
return verifyFiles

def testCodeRetour():
myPath = ProcessFile.returnPath()
print(myPath)

你知道它是如何工作的吗?

感谢您的帮助

最佳答案

列表pathFiles= []从未被使用过。也许你想在其中添加一些东西?如果是这种情况,那么您必须修复一些问题。

在循环中:

for name in files:
pathFiles= os.path.join(root, name)
print(pathFiles)

将名称 pathFiles 更改为 pathFile,然后将其附加到列表中。

for name in files:
pathFile= os.path.join(root, name)
print(pathFile)
pathFiles.append(pathFile)

关于python - 从函数返回所有路径值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55223911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com