0

what I'm trying is to find the highest number of the files that I have in the folder. Once decleared the path of the folder, I tried to add the name of the files that I want to read. In that file I want to find any possible number from one to more digits.

path = "C:/Users/Desktop/Data/noupdated/FEB/batch/csv/"
files = glob.glob(path + "noupdated_\d+_FEB_españa_info_csv.csv")
for file in files:
    print(file)

It should be printing in this case, the following outcome:

"C:/Users/Desktop/Data/noupdated/FEB/batch/csv/noupdated_0_FEB_españa_info_csv.csv"
"C:/Users/Desktop/Data/noupdated/FEB/batch/csv/noupdated_1_FEB_españa_info_csv.csv"

But instead, it's not printing anything.

Thank you! I'm relatively new with the regex syntax.

  • 3
    Globs have *absolutely nothing* to do with regex. `\d+` in a glob matches filenames literally containing `\d+`, because none of those characters have any particular meaning here. – jasonharper Jun 06 '22 at 15:35
  • You are using REGEX syntax within a glob which isn't recognized: https://stackoverflow.com/questions/13031989/regular-expression-usage-in-glob-glob – Cargo23 Jun 06 '22 at 15:40
  • Does this answer your question? [Regular expression usage in glob.glob?](https://stackoverflow.com/questions/13031989/regular-expression-usage-in-glob-glob) – Amit Gupta Jun 06 '22 at 15:41
  • Alright, when I was learning the regex, they combine it with the glob functions, so I expected the same behaviour, but as I've been looking more into it; there are some differences. So I worked it out this way. "noupdated_[0-9]*_FEB_españa_info_csv.csv" ¡Thank you all for the help! – PedroSanchez95 Jun 06 '22 at 16:01

0 Answers0