import os your_file_path = "D:yourdirpathfile.csv" print(f"Dir:{os.path.dirname(your_file_path)}") #>>> Dir:D:yourdirpath