Answers for "python show directory"

24

get wd in python

import os

path = os.getcwd()

print(path)
# /Users/mbp/Documents/my-project/python-snippets/notebook

print(type(path))
# <class 'str'>
Posted by: Guest on January-26-2020
14

get list of folders in directory python

import os 
my_list = os.listdir('My_directory')
Posted by: Guest on June-08-2020
15

working directory python

import os
cwd = os.getcwd()
Posted by: Guest on March-09-2020
8

get directory of file python

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))
Posted by: Guest on April-03-2020
0

how to see directory from os module

import pathlib

# define the path
currentDirectory = pathlib.Path('.')

# define the pattern
currentPattern = "*.py"

for currentFile in currentDirectory.glob(currentPattern):
    print(currentFile)
Posted by: Guest on January-20-2021

Code answers related to "python show directory"

Python Answers by Framework

Browse Popular Code Answers by Language