Walk directories and create pdf from images

The way your code is currently:

for X in range(1, 397):
    dirname = os.path.join('./','BetaX', '')
    output  = os.path.join('./','BetaX', '/output.pdf')

The X is just a character in the string BetaX. You need to cause X to be treated like an integer value and then you need to concatenate that value onto Beta to come up with your full folder name.

Also, you don’t want the slashes in what you’re passing to os.path.join. The point of the join call is to hide the details of the path separator character. The value of output will be just /output.pdf with what you have, as the third parameter will be considered an absolute path because of the slash at the front of it.

Here’s that part of your code with both of these issues addressed:

for X in range(1, 397):
    dirname = os.path.join('.','Beta' + str(X), '')
    output  = os.path.join('.','Beta' + str(X), 'output.pdf')

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top