Answered by : matthew-bourke
import os
files = os.listdir('.')
print(files)
for file in files: # do something
Source : | Last Update : Wed, 11 Nov 20
Answered by : jonathan-steele
from shutil import copyfile
copyfile(src, dst)
Source : https://stackoverflow.com/questions/123198/how-do-i-copy-a-file-in-python | Last Update : Mon, 09 Mar 20
Answered by : blushing-badger-gx3qb8p1v3db
import os
print(os.listdir('/path/to/folder/to/list'))
Source : | Last Update : Wed, 29 Apr 20
Answered by : jasmine-bhanushali
import os
folder_path = "./folder-path"
for path, currentDirectory, files in os.walk(folder_path): for file in files: if not file.startswith("."): print(os.path.join(path, file))
Source : | Last Update : Fri, 21 Oct 22
Answered by : georgiy-kantsedal
import glob
print(glob.glob("/home/adam/*"))
Source : | Last Update : Wed, 23 Mar 22
Answered by : excited-eagle-w9stcl6o7xop
import os
path = '/folder1/folder2/'
files = os.listdir(path)
Source : | Last Update : Wed, 27 Jan 21
Answered by : determined-dolphin-jsoserb5x5ka
from os import listdir
file_list = listdir(folder_path)
Source : https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory | Last Update : Wed, 27 Jan 21
Answered by : spotless-swan-f7m0lmzpi0q6
lstJson = [f for f in os.listdir(str(self.pathJson)) if f.endswith('.json')] return lstJson
Source : | Last Update : Sun, 04 Apr 21
Answered by : shy-stag-diov9puelbi3
"""Examples from SO (see link)
Obviously the directory can be any directory with 'read access' (not only `os.curdir`)
Doc about the `os` module: https://docs.python.org/3/library/os.html
"""
# /!\ Return a `filter` object, not a `list`
import os
files_ex1 = filter(os.path.isfile, os.listdir(os.curdir))
# List comprehension
files_ex2 = [f for f in os.listdir(os.curdir) if os.path.isfile(f)]
Source : https://stackoverflow.com/questions/11968976/list-files-only-in-the-current-directory | Last Update : Sat, 13 Nov 21
Answered by : different-dormouse-0a8c01ggfm3r
from os import walk
f = []
for (dirpath, dirnames, filenames) in walk(mypath): f.extend(filenames) break
Source : https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory | Last Update : Wed, 02 Feb 22