How to get Base common folder from list of folder using Python?

Question:

THere is a list of file names from several folders/subfolders (Same drive). Example :

C:TestGOabc.csv
C:TestTEST2TER.abc.csv
C:TestCARabc.cvs

I need to get ‘C:Test’ as the shared root folder of the list of the above files. Is there any python function already there ?

Asked By: PCG

||

Answers:

os.path.commonpath(["C:Test...", "..."])
Answered By: Ibolit
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.