Amin Ali
Amin Ali

Reputation: 55

How to extract folder name in python?

My folder name as movie title and after extracting movie name as folder in python then it will be use as a movie title to find out the movie discription by usnibg omdb API and then find out the rate of the movie when we seen the movie rate then the folder will be deleted

Upvotes: 0

Views: 149

Answers (1)

Saige Zhang
Saige Zhang

Reputation: 787

os.walk(top, topdown=Ture, onerror=None, followlinks=False)

The walk() function in module os can traverse all files in a folder.

The function returns a tupple(dirpath, dirnames, filenames).

Parameters:

dirpath:string, the path of directory,

dirnames:list, includes all directories’ name

filenames:list,includes all files’ name.

p.s.

dirnames and filenames didn’t include the path information, if you need entire path, use os.path.join(dirpath, dirnames)

Upvotes: 1

Related Questions