Answers for "pathlib get all file in a folder"

5

find all files in a directory with extension python

import glob, os
os.chdir("/mydir")
for file in glob.glob("*.txt"):
    print(file)
Posted by: Guest on March-06-2020
2

python import all files in directory

# Basic syntax:
import glob # Package for Unix-style pathname pattern expansion
import os   # Python operating system interface

directory = '/path/to/directory/with/files/'
# Obtain list of filenames that end in .txt in the directory
all_files = glob.glob(os.path.join(directory, "*.txt"))
# Where os.path.join creates the os-specific path to each file

# Import data however you like. To append data in a single pandas 
# dataframe and a single list, you can do:
your_list = [ ]
for filename in all_files:
    dataframe = pd.read_csv(filename, index_col=None, header=0, sep="\t")
    your_list.append(dataframe)
Posted by: Guest on May-12-2021
1

how to get all folders on path in python

os.walk(directory)
[x[0] for x in os.walk(directory)]
Posted by: Guest on February-10-2020

Code answers related to "pathlib get all file in a folder"

Python Answers by Framework

Browse Popular Code Answers by Language