Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Listing files with glob.
#7
Aaah, pattern is only for recursive search.

This is like doing globbing in the bash shell. Should make it easy to test. ls pattern,

I don't think you can do what you want to do, but you can do something close. The pattern is character based and it is not going to understand integers at all. But you can specify patterns that will match an integer range, just not any range. If you wanted to match 10 through 20 your pattern would be '*000[1-2][0-9].txt$'. This says match any number of characters followed by 000 then a 1 or 2, then any number 0-9 and ending with .txt.

I do not see how I could make my range 1..15 though, or 15..25 where part of the match depends on how the previous match was achieved. If my range is 10..20, the first digit has to be 1 or 2, but the range of the second digit is 0-9 if the first digit is 1, but only 0-5 if the first digit is 2.

I think this is easier solved by parsing the filenames yourself. Extract the part of the filename that is digits, convert to an integer and compare to your range. You could use glob to limit the files you test to only those that match your naming patter '*[0-9][0-9][0-9][0-9][0-9].txt$'
Reply


Messages In This Thread
Listing files with glob. - by MathCommander - Aug-10-2020, 02:47 PM
RE: Listing files with glob. - by deanhystad - Aug-10-2020, 02:55 PM
RE: Listing files with glob. - by MathCommander - Aug-10-2020, 03:39 PM
RE: Listing files with glob. - by deanhystad - Aug-10-2020, 04:43 PM
RE: Listing files with glob. - by MathCommander - Aug-10-2020, 04:59 PM
RE: Listing files with glob. - by bowlofred - Aug-10-2020, 06:22 PM
RE: Listing files with glob. - by deanhystad - Aug-10-2020, 06:44 PM
RE: Listing files with glob. - by DeaD_EyE - Aug-10-2020, 11:05 PM
RE: Listing files with glob. - by snippsat - Aug-12-2020, 08:20 AM
RE: Listing files with glob. - by MathCommander - Oct-26-2020, 02:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Listing directories (as a text file) kiwi99 1 853 Feb-17-2023, 12:58 PM
Last Post: Larz60+
  Read directory listing of files and parse out the highest number? cubangt 5 2,416 Sep-28-2022, 10:15 PM
Last Post: Larz60+
  |SOLVED] Glob JPGs, read EXIF, update file timestamp? Winfried 5 2,520 Oct-21-2021, 03:29 AM
Last Post: buran
  [SOLVED] Input parameter: Single file or glob? Winfried 0 1,599 Sep-10-2021, 11:54 AM
Last Post: Winfried
  q re glob.iglob iterator and close jimr 2 2,264 Aug-23-2021, 10:14 PM
Last Post: perfringo
  Listing All Methods Of Associated With A Class JoeDainton123 3 2,384 May-10-2021, 01:46 AM
Last Post: deanhystad
  Listing data from a list ebolisa 1 1,757 Sep-29-2020, 02:24 PM
Last Post: DeaD_EyE
  Listing Attributes of Objects & Classes JoeDainton123 4 2,374 Aug-28-2020, 05:27 AM
Last Post: ndc85430
  Listing groups tharpa 2 2,594 Nov-26-2019, 07:25 AM
Last Post: DeaD_EyE
  Version of glob for that Supports Windows Wildcards? Reverend_Jim 5 5,690 Jun-18-2019, 06:31 PM
Last Post: Reverend_Jim

Forum Jump:

User Panel Messages

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