1

I would like to know how to retrieve all the values of my loop via a Return. In my first function, I loop to recover all my folders, subfolders. Then I go back to pathFiles

In my second function, I test my linux command on all files in folders, but the problem is this: my function only tests the last result of my loop and not all values.

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)

Do you have any idea how it works?

Thank you for your help

  • `Do you have any idea how it works?` - Did you write that code? – wwii Mar 18 '19 at 14:56
  • Do you ever intend to make a `ProcessFile` instance? Or are you just using it to *contain* those static methods? Typically in Python you wouldn't make a class with only static methods - you would write the methods as *standalone* functions and the variables in their own module then import the module. – wwii Mar 18 '19 at 15:02
  • [Using classes with only static methods for organizational purposes?](https://stackoverflow.com/q/53529034/2823755) | [module with classes with only static methods](https://stackoverflow.com/q/21883511/2823755) | [a class with all static methods (closed)](https://stackoverflow.com/q/42757961/2823755) – wwii Mar 18 '19 at 15:07

1 Answers1

0

The list pathFiles= [] is never used. Maybe you want to append something in it? If this is the case then you have to fix a couple of things.

In the loop:

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

Change the name pathFiles to pathFile and then append it to the list.

for name in files:
    pathFile= os.path.join(root, name)
    print(pathFile)
    pathFiles.append(pathFile)
alec_djinn
  • 10,104
  • 8
  • 46
  • 71