Skip to content
  • View menu
  • View sidebar

bioinfo core

Index & solution of bioInfo utilities

  • Home
  • All entries
  • Blogs
  • Contact
  • About

Categories

  • Between languages (7)
  • Blogs (8)
  • Python (35)
  • R (1)
  • Unix (37)

Tags

bedfile Blogs conda Excel html numpy Pandas Python R slurm Unix
04/22/202010/21/2021 by bioinfocore

Python list files from a directory

  • Python
  • Python

Use os.listdir(), listing files in current directory:

import os
arr = os.listdir()
print(arr)

Use glob, listing by regular expression:

import glob

listFiles = []
for file in glob.glob("*.txt"):
    listFiles.append(file)

Source has an excellent answer to this question, further usage can be found in the source.

Source:
https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory

Post navigation

← Previous Post Pandas add an empty row or column to a dataframe with index
Next Post → Unix store a list of files into an array variable
Copyright 2022 | by bioinfocore