SubhanUllah Posted October 17, 2022 Report Posted October 17, 2022 import os full_path = '/home/User/Documents/file.txt' head_tail = os.path.split(full_path) print (f"The full path is '{full_path}’") print (f"The path is '{head_tail[0]}'") print(f"and the file name is '{head_tail[1]}’ ") output: The full path is '/home/User/Documents/file.txt’ The path is '/home/User/Documents' and the file name is 'file.txt’ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.