Answers for "get folder of file python"

8

get directory of file python

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

python get full path

import os
# you have to be in the same directory as the file
file = 'myfile.txt'
# or also
file = 'directory/to/myfile.txt'

path = os.path.abspath(file)
Posted by: Guest on May-16-2020
-3

get pyhton file path python

import os

os.path.realpath(__file__)
Posted by: Guest on October-13-2020
1

python get files in directory

from pathlib import Path
for txt_path in Path("/path/folder/directory").glob("*.txt"):
  print(txt_path)
Posted by: Guest on November-30-2020
0

python get files in directory

(_, _, filenames) = os.walk(mypath).next() #if you are confident that the walk will return at least one value
Posted by: Guest on August-31-2021

Code answers related to "get folder of file python"

Python Answers by Framework

Browse Popular Code Answers by Language