Python Forum
search and read file given partial file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
search and read file given partial file
#1
Hi,
I want to read file given a partial file name:

import glob
my_dir = 'D:\PythonCodes'
#post_fix = ['\InputFiles\KYLJHQ_20191215\sub_folder/InputCSV.csv','\InputFiles\KYLJHQ_20191215\sub_folder/InputCSV2.csv']
post_fix = ['\InputFiles\KYLJHQ_*\sub_folder/InputCSV.csv','\InputFiles\KYLJHQ_*\sub_folder/InputCSV2.csv']


for i in range(len(post_fix)):
    full_path = glob.glob(my_dir + str(post_fix[i]))
    tmp_file = open(full_path,'r')
    tmp_data = tmp.readlines()
    print(tmp_data)
the file structure is D:\PythonCodes -->\InputFiles\KYLJHQ_*\sub_folder/InputCSV.csv. I uae above code but it giving error:

TypeError: expected str, bytes or os.PathLike object, not list
Reply


Messages In This Thread
search and read file given partial file - by SriRajesh - Jan-07-2020, 01:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 254 May-03-2024, 07:23 AM
Last Post: Pedroski55
  partial functions before knowing the values mikisDeWitte 4 665 Dec-24-2023, 10:00 AM
Last Post: perfringo
  file open "file not found error" shanoger 8 1,265 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Recommended way to read/create PDF file? Winfried 3 2,960 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,585 Nov-09-2023, 10:56 AM
Last Post: mg24
  Search Excel File with a list of values huzzug 4 1,312 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Move Files based on partial Match mohamedsalih12 2 881 Sep-20-2023, 07:38 PM
Last Post: snippsat
  Need to replace a string with a file (HTML file) tester_V 1 800 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  Search for multiple unknown 3 (2) Byte combinations in a file. lastyle 7 1,451 Aug-14-2023, 02:28 AM
Last Post: deanhystad
  How can I change the uuid name of a file to his original file? MaddoxMB 2 984 Jul-17-2023, 10:15 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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