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 : charming-caribou-khynop2559q4
import os
def get_filepaths(directory): """ This function will generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames). """ file_paths = [] # List which will store all of the full filepaths. # Walk the tree. for root, directories, files in os.walk(directory): for filename in files: # Join the two strings in order to form the full filepath. filepath = os.path.join(root, filename) file_paths.append(filepath) # Add it to the list. return file_paths # Self-explanatory.
# Run the above function and store its results in a variable.
full_file_paths = get_filepaths("/Users/johnny/Desktop/TEST")
Source : https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory | Last Update : Thu, 02 Apr 20
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 : 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 : 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 : 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 : 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
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