Python Forum
How to get the file path and full file name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get the file path and full file name
#9
It's unclear how code supposed to work, but there is glob:

glob.glob('*config_file*')    # returns list of matching filenames in current directory
glob.glob('*config_file*')[0] # if you are sure that there is only one matching file
glob.glob(r'D:\mainfolder\*config_file*') # should work, I am not using Windows, returns list of paths
glob.glob(r'D:\**\*config_file*', recursive=True) # search recursively in D subfolders
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
How to the file location - by SriMekala - May-16-2019, 01:08 PM
RE: How to get the file path and full file name - by perfringo - May-19-2019, 07:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write variable in a python file then import it in another python file? tatahuft 4 970 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,093 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 1,015 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  import a function from another file using relative path paul18fr 6 3,152 Aug-01-2024, 06:40 AM
Last Post: paul18fr
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 6,538 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  file open "file not found error" shanoger 8 8,055 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Need to replace a string with a file (HTML file) tester_V 1 1,957 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can I change the uuid name of a file to his original file? MaddoxMB 2 2,184 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  File path by adding various variables Mishal0488 2 3,994 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 2,133 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020