Search code examples
pythonlistdir

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


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

C:\Test\GO\abc.csv
C:\Test\TEST2\TER.abc.csv
C:\Test\CAR\abc.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 ?


Solution

  • os.path.commonpath(["C:\Test...", "..."])