Reputation: 199
I have the following code:
ctypes.windll.user32.MessageBoxW(0, "Please choose a file directory", "File directory", 1)
EDS_database_path = filedialog.askdirectory()
EDS_answer = simpledialog.askstring("Input", "Please enter the ID")
EDS_files_list = glob.glob(EDS_database_path+'/**'+EDS_answer+'**', recursive = True)
print(EDS_files_list)
In the output I get:
['X:/data/Folder\\afilewithIDnumber.txt','X:/data/Folder\\anotherfilewithIDnumber.txt',]
So the function worked well but I want to get rid of "\" and replace it with "/" as I explicitly wanted to do in my function.
Upvotes: 0
Views: 616
Reputation: 2369
You can use print([filename.replace("\\", "/") for filename in EDS_files_list])
instead of print(EDS_files_list)
. This will replace all instances of \\
in the strings with /
, which will make it output like you want it to.
Upvotes: 1
Reputation: 37
you can use the pathlib package in python3 as it the new normal for dealing with paths
Upvotes: 0