I have posted an example below and the desired result .
I saw a number of ways to eliminate the path section of the file but not the vice versa
Example .
sample = "/tmp/test/helloworld.cpp"
sample = truncate_file_name(sample)
Print sample
Desired result
/tmp/test
os.pathprovides thedirnamefunction: