Python Forum
Read directory listing of files and parse out the highest number?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read directory listing of files and parse out the highest number?
#4
Just an idea: for every filename which ends with _.csv strip the specific characters, convert to int and find max value:

filenames = ["igMess_2_.csv", "igMess_3_.csv", "igMess_1_.csv", "igMess_5.csv"]

max_value = max(int(filename.strip('igMess_.csv')) for filename in filenames if
       filename.endswith("_.csv"))

# max_value would in this example be 3
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
RE: Read directory listing of files and parse out the highest number? - by perfringo - Sep-28-2022, 01:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop through all files in a directory? Winfried 10 436 Apr-23-2024, 07:38 PM
Last Post: FortuneCoins
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 471 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  change directory of save of python files akbarza 3 906 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,397 Jun-27-2023, 01:17 PM
Last Post: diver999
  parse/read from file seperated by dots giovanne 5 1,128 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Monitoring a Directory for new mkv and mp4 Files lastyle 3 1,660 May-07-2023, 12:33 PM
Last Post: deanhystad
  Listing directories (as a text file) kiwi99 1 848 Feb-17-2023, 12:58 PM
Last Post: Larz60+
  How to read in mulitple files efficiently garynewport 3 899 Jan-27-2023, 10:44 AM
Last Post: DeaD_EyE
  python read iperf log and parse throughput jacklee26 4 2,803 Aug-27-2022, 07:04 AM
Last Post: Yoriz
  How to read python shortcut target profile directory of Chrome Ink file sunny9495 1 1,673 Apr-12-2022, 06:12 PM
Last Post: sunny9495

Forum Jump:

User Panel Messages

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