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?
#2
new detail

So it would def need to look at ONLY files that start with igMess and contain 2 underscores ( _ )
seems we have older files that are formatted like this:
igMess_1.csv
igMess_2.csv

The newer format is:
igMess_1_.csv
igMess_2_.csv

So only care to look at these and return the next highest number.

I have this sample script im playing around with, but not sure how to only consider the files with 2 of those underscores.

# iterate over files in
# that directory
for filename in os.listdir(directory):
    f = os.path.join(directory, filename)
    d = filename
    # checking if it is a file
    if d.startswith("igMess_"):
        print(d)
Reply


Messages In This Thread
RE: Read directory listing of files and parse out the highest number? - by cubangt - Sep-27-2022, 08:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Filer and sort files by modification time in a directory tester_V 5 338 May-02-2024, 05:39 PM
Last Post: tester_V
  Loop through all files in a directory? Winfried 10 536 Apr-23-2024, 07:38 PM
Last Post: FortuneCoins
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 506 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  change directory of save of python files akbarza 3 970 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,531 Jun-27-2023, 01:17 PM
Last Post: diver999
  parse/read from file seperated by dots giovanne 5 1,160 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Monitoring a Directory for new mkv and mp4 Files lastyle 3 1,697 May-07-2023, 12:33 PM
Last Post: deanhystad
  Listing directories (as a text file) kiwi99 1 868 Feb-17-2023, 12:58 PM
Last Post: Larz60+
  How to read in mulitple files efficiently garynewport 3 918 Jan-27-2023, 10:44 AM
Last Post: DeaD_EyE
  python read iperf log and parse throughput jacklee26 4 2,864 Aug-27-2022, 07:04 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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