I got always the message: PermissionError: [WinError 32] The process cannot access the file because it is being used by another process Yes, i read [enter link description here][1] but it didn't help me.
# pdf_merger2.py
import glob,os,shutil
os.getcwd()
from PyPDF2 import PdfFileMerger
os.chdir(r"auf_comp")
def merger(output_path, input_paths):
pdf_merger = PdfFileMerger()
file_handles = []
for path in input_paths:
pdf_merger.append(path)
with open(output_path, 'wb') as fileobj:
pdf_merger.write(fileobj)
if __name__ == '__main__':
paths = glob.glob('*.pdf')
paths.sort()
merger('data.pdf', paths)
shutil.move(r"data.pdf", r"../data.pdf")
edit:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\shutil.py", line 788, in move
os.rename(src, real_dst)
PermissionError: [WinError 32] PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'data.pdf' -> '../data.pdf'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\typ42\Downloads\latextest\merge.py", line 22, in <module>
shutil.move(r"data.pdf", r"../data.pdf")
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\shutil.py", line 803, in move
os.unlink(src)
PermissionError: [WinError 32] PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'data.pdf'
[1]: https://stackoverflow.com/questions/27215462/permissionerror-winerror-32-the-process-cannot-access-the-file-because-it-is