Answers for "listdir only files"

18

python list files in current directory

import os

files = os.listdir('.')
print(files)
for file in files:
  # do something
Posted by: Guest on November-04-2020
1

list only directories

# List directories under the current working directory.
ls -l | grep "^d"

# List directories under the current working directory and 
# include hidden folders
ls -la | grep "^d"
Posted by: Guest on October-09-2020
0

find only list directories

find . -maxdepth 1 -type d -iname "<regex>" -printf '%f\n'
Posted by: Guest on July-29-2021

Python Answers by Framework

Browse Popular Code Answers by Language