Rick Segal
Rick Segal

Reputation: 60

In Python how do you use filedialog.askopenfilename() to get just the file name itself

I have successfully managed to get tkinter's filedialog imported and used the command

file_found = filedialog.askopenfilename()
print(file_found)

Dialog box opens, I can select and successfully print the full path/file name. What I want to do next is just use the file name so I can use os.rename to change the file's name.

A pointer to the documentation or the how would be gratefully appreciated.

Thank you.

Upvotes: 0

Views: 1066

Answers (1)

Tim Roberts
Tim Roberts

Reputation: 54787

os.path.basename(file_path) will that job. The name comes from the bash basename command, which serves the same purpose.

Upvotes: 2

Related Questions