Python Forum
Matching two files based on a spited elements
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matching two files based on a spited elements
#6
You guys are awesome!
Each time I have a problem with a code I come here, I always get helped without an 'attitude' of the 'StackOverflow.
And even more, I get much-needed coaching...

To ibreeden:
Thank you! I'm confused about flags, totally missed it Confused

The files I'm working with are changing file Names each time a new file added to the file's directory but the timestamp is staying the same.
The file "\\D1376\d$\logs\BBLog.1.xml,05/28/2021 17:02:03" will be "\\D1376\d$\logs\BBLog.5.xml,05/28/2021 17:02:03" tomorrow or "\\D1376\d$\logs\BBLog.25.xml,05/28/2021 17:02:03" in a week.
To find it tomorrow or in a week I must keep a file's list of yesterday's with the timestamps. That is why I'm using a 'timestamp' as an identifier of a file, not the filename. I'm not sure it is the best way to do this kind of search but this is what I came up with.

To snippsat:
Thank you for the snippet!
I see your point and I was thinking about using 'set' but not sure it will do the job when the names of the files I'm working with are changing and only the timestamp stays the same.
tod = set((line.strip() for line in open('tod1376.txt')))
yrd = set((line.strip() for line in open('yrd1376.txt')))

with open('File_diff.txt', 'w') as diff:
    for line in tod:
        if line not in yrd:
            diff.write(line)               
            print(f"{line}")  
Thank you again!
ibreeden likes this post
Reply


Messages In This Thread
RE: Matching two files based on a spited elements - by tester_V - May-30-2021, 07:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy Paste excel files based on the first letters of the file name Viento 2 449 Feb-07-2024, 12:24 PM
Last Post: Viento
  unable to remove all elements from list based on a condition sg_python 3 451 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Move Files based on partial Match mohamedsalih12 2 832 Sep-20-2023, 07:38 PM
Last Post: snippsat
  Making a question answering chatbot based on the files I upload into python. Joejones 1 1,232 May-19-2023, 03:09 PM
Last Post: deanhystad
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,157 May-17-2022, 11:38 AM
Last Post: Larz60+
  Replace elements of array with elements from another array based on a third array Cola_Reb 6 1,879 May-13-2022, 06:06 PM
Last Post: deanhystad
Question Change elements of array based on position of input data Cola_Reb 6 2,139 May-13-2022, 12:57 PM
Last Post: Cola_Reb
  select Eof extension files based on text list of filenames with if condition RolanRoll 1 1,529 Apr-04-2022, 09:29 PM
Last Post: Larz60+
  Finding files matching pattern GrahamL 1 1,294 Jan-14-2022, 01:16 PM
Last Post: DeaD_EyE
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,508 Dec-18-2021, 09:32 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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