mukstik
mukstik

Reputation: 11

Passing a string variable to glob

I'm trying to pass a directory to glob which will be read to a variable from a config file.

If I just do this it works fine:

path = '//Server/Company/Official Documents/**/*.pdf'
Files = glob.glob(path,recursive=True)

But if I try to do this I get an empty list:

path = Config[1][1]
Files = glob.glob('{path}**/*.pdf'.format(path=path),recursive=True)

For information,

print(Config [1][1])

gives this

'//Server/Company/Official Documents/'

Upvotes: 1

Views: 2066

Answers (1)

Umesh
Umesh

Reputation: 971

You are missinng / in '{path}**/*.pdf'.format(path=path) Try changinng it to:


'{path}/**/*.pdf'.format(path=path1)

like:

glob.glob('{path}/**/*.pdf'.format(path=path),recursive=True)


Upvotes: 1

Related Questions