Skip to main content
edited tags
Link
Graipher
  • 41.7k
  • 7
  • 70
  • 134
edited tags; edited title
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481

Change code to avoid side-effects Recursively list files within a directory

added 72 characters in body
Source Link
FXux
  • 175
  • 2
  • 8

I have the following code to recursively list files within a directory:

from fnmatch import filter
from os      import path, walk

def files_within(directory_path):
  files_within = []
  for root, directory_path, files_path in walk(directory_path):
    for file_path in filter(files_path, "*"):
      files_within.append(path.join(root, file_path))
  return files_within

I want change it to avoid side affects. Is it possible?

I'm not using the glob because I'm using Python 2.5 because of a legacy code.

I have the following code to recursively list files within a directory:

def files_within(directory_path):
  files_within = []
  for root, directory_path, files_path in walk(directory_path):
    for file_path in filter(files_path, "*"):
      files_within.append(path.join(root, file_path))
  return files_within

I want change it to avoid side affects. Is it possible?

I'm not using the glob because I'm using Python 2.5 because of a legacy code.

I have the following code to recursively list files within a directory:

from fnmatch import filter
from os      import path, walk

def files_within(directory_path):
  files_within = []
  for root, directory_path, files_path in walk(directory_path):
    for file_path in filter(files_path, "*"):
      files_within.append(path.join(root, file_path))
  return files_within

I want change it to avoid side affects. Is it possible?

I'm not using the glob because I'm using Python 2.5 because of a legacy code.

Grammar; noise reduction; Removed incorrect python 2.6 tag
Source Link
Vogel612
  • 25.5k
  • 7
  • 59
  • 141
Loading
Source Link
FXux
  • 175
  • 2
  • 8
Loading