Skip to content
Advertisement

How can I interchangeably use glob.glob(“*PDF) and os.listdr(“./directory”)?

I am trying to merge PDF files inside a folder

I tried running the code from the same directory and it worked however when I copied the code to a different location and specified the directory path of PDF files, the merging process is not happening and I keep getting errors.

JavaScript

This is the code that I wrote when I went one folder up with my source code folder location

JavaScript

For this reason I am running all of my codes from inside my PDF folders and I know it’s not a good practice.

Can anyone help me to resolve this issue, I am only in my early learning phase.

I also tried this

JavaScript

Advertisement

Answer

glob.glob returns the full path to the file while os.listdir only gives the file name. Just stick with glob.

JavaScript

Another nice option is the pathlib module.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement