Permissionerror: [Winerror 32] Another program is using this file, the process is unable to access

tags: Error analysis  PyPDF2  python

I found a problem when I was consolidated today, and I couldn't delete the source file after I merged the PDF file.

Permissionerror: [Winerror 32] Another program is using this file, the process is unable to access

This error has occurred, and I tried to delete the source file manually, and the file has been opened by Python and the prompt that cannot be operated.

explain

Lite mean, this file has been occupied, you can't access him.

Code

def merge_pdf(name,file_all,target_path):
    total=PdfFileWriter()
    totalPages=0
    for pdf_file in file_all:                  
        print(pdf_file)            
        # Read PDF files
        pic=open(pdf_file,'rb')            
        input_pdf=PdfFileReader(pic)
                 # Get the number of pdf total pages
        pagecount=input_pdf.getNumPages()
        print(pagecount)
        totalPages+=pagecount
                 # Traversing each PDF file
        for iPage in range(pagecount):
                         #        
            total.addPage(input_pdf.getPage(iPage))
        #pic.close()
        #os.remove(pdf_file)    
         Print (Totalpages, 'Sharing PDF file merge ...')
    target_name=name+'.pdf'
    
    new=os.path.join(target_path,target_name)
    with open(new,'wb') as outputfile:
        total.write(outputfile)

reason

The reason is that I didn't turn it off after reading the feeding file, causing him to have a cache.

I tried to turn off the delete operation in the comment location, I successfully deleted the source PDF file.

But I am surprised to find that the merged documents are all blank.

It turned out that I deleted the source file, causing no data when writing.

solve

I am inserting a write operation before turning off.

The purpose of deleting the source file after successfully reaching the merger.

Intelligent Recommendation

python3.7: PermissionError: [WinError 32] The process cannot access the file because it is......

Problem Description: Python3.7, using the library image inside PIL just wants to get the length and wide of the picture Newspaper is wrong D:\Python37-32\python.exe D:/pyFile/python_script/img_read.py...

[Winerror 32] Another program is using this file, the process cannot be accessed, # image processing

When making image processing, I used three modules OS, PIL, CV2. I encountered a bug who plagued one morning, I investigated several resource monitor ~~~, bug as follows: Description of Requirement: 1...

Windows Subsystem Launch Ubuntu "Another program is using this file, the process is unable to access"

Background & Issue After the disk is finished, the WSL cannot be started. Tip "Another program is using this file, the process is unable to access." solve Restarting and resource managem...

Windows version Kafka exception java.nio.file.filesystemException Another program is using this file, the process is unable to access

  content   surroundings Phenomenon reason Solution Problem correction delete file log refer to     surroundings Windows2012 R2 kafka_2.12-2.3.0   Phenomenon reason Kafka Prof...

Solve the ASP.NET Core Deployment to IIS, Update Projects "Another program is using this file, the process is unable to access"

Article catalog Foreword First, solve the idea Second, the answer 3. Reference documentation Foreword Deploying an ASP.NET Core project on IIS, an error that occupies the process during the update Fir...

More Recommendation

Python using multiprocessing.Manager appears PermissionError: [WinError 5] Access denied.

Run from Liao Xuefeng tutorialDistributed process Example, PermissionError: [WinError 5] when running in the windows environment Error log: Running cmd and powershell with administrator privileges sti...

Kafka starts an exception: Error Failed to Clean Up log for __consumer_offsets-30 in Dir Another program is using this file, the process is unable to access

problem : Today to start Kafka failure Problem Description: When you start Kafka, then view the log, the wrong point is as follows: Originally: If this problem, I haven't found specific reasons, and t...

[ ]permissionerror winerror 5 Access denied.

forward from:Gentle and easy to light - windows pip install python module error summary Foreword: Put python these daysversion upgradeAfter that, I found that many of the pip installation modules were...

PermissionError: [WinError 5] Access denied.

cookie acquisition Traceback (most recent call last): File “C:\Users\15300\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\service.py”, line 76, in start...

PermissionError: [WinError 5] Access is denied

An error "PermissionError: [WinError 5] Access Denied" occurred during pip installation. Solution: 1. Cut to the directory shown by the arrow, and everyone will be slightly different. This &...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top