-3

Given a random length of filepath, how to regex for something in the middle:

name = 'path/to/../../foo/file.py'

something like this:

In [2]: name.startswith('.*/foo/')
Out[2]: False
A. Archer
  • 85
  • 2
  • 10

1 Answers1

0

Instead of using re Use glob as the way to do it.

import glob
for filename in glob.iglob('C:\Users\Desktop\**\Start\c*'):
    print(filename)

output

C:\Users\Desktop\screenshoots\Start\cmr(1).PNG
C:\Users\Desktop\screenshoots\Start\cmr(2).PNG
C:\Users\Desktop\screenshoots\Start\cmr(3).PNG
Ravichandra
  • 2,162
  • 4
  • 24
  • 36