Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Listing files with glob.
#1
Hi. I have a directory wich contains a set of files with the following format

"name" + "six digits number" + ".txt"

The following names are examples of this format

dog000001.txt

cat000054.txt

lion010101.txt

mouse123456.txt

I have to make a list of all the files whose end number belongs to an interval. To get this, I have used the following instruction

files_list = glob.glob('*' + '[' + initial + '-' + final + ']' + '.txt')
where initial and final are the left and right boundaries of the interval, respectively. For example, if I execute the before instruction with

initial = '000000'
final = '010000'
the execution would return to me the following result

files_list = [dog000001.txt, cat000054.txt]
but it doesn't occur. I have tried using ranges too but the range doesn't consider 6 digits if the number has less than 6 digits.

Can anybody help me?

Thanks.
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 930 Feb-17-2023, 12:58 PM
Last Post: Larz60+
  Read directory listing of files and parse out the highest number? cubangt 5 2,618 Sep-28-2022, 10:15 PM
Last Post: Larz60+
  |SOLVED] Glob JPGs, read EXIF, update file timestamp? Winfried 5 2,657 Oct-21-2021, 03:29 AM
Last Post: buran
  [SOLVED] Input parameter: Single file or glob? Winfried 0 1,641 Sep-10-2021, 11:54 AM
Last Post: Winfried
  q re glob.iglob iterator and close jimr 2 2,346 Aug-23-2021, 10:14 PM
Last Post: perfringo
  Listing All Methods Of Associated With A Class JoeDainton123 3 2,464 May-10-2021, 01:46 AM
Last Post: deanhystad
  Listing data from a list ebolisa 1 1,813 Sep-29-2020, 02:24 PM
Last Post: DeaD_EyE
  Listing Attributes of Objects & Classes JoeDainton123 4 2,457 Aug-28-2020, 05:27 AM
Last Post: ndc85430
  Listing groups tharpa 2 2,676 Nov-26-2019, 07:25 AM
Last Post: DeaD_EyE
  Version of glob for that Supports Windows Wildcards? Reverend_Jim 5 5,813 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