Error 32, Python, file being used by another process

前端 未结 3 823
死守一世寂寞
死守一世寂寞 2021-02-19 09:37

I have a simple program, which looks for all compressed folders in a directory, targets one compressed file, gets an excel file located inside the compressed file and moves it t

相关标签:
3条回答
  • 2021-02-19 10:12

    downloaded files must be marked as 'unblock' in the properties window of the file before they can be worked with code.

    0 讨论(0)
  • 2021-02-19 10:24
    path = 'C:\Users\me\Documents\Extract'
    destination_path = 'C:\Users\me\Documents\Test'
    i = 0
    for folder in os.listdir(path):
        path_to_zip_file = os.path.join(path, folder)
    
        zfile = zipfile.ZipFile(path_to_zip_file)
        for name in zfile.namelist():
            if name.endswith('.xls'):
                new_name = str(i)+'_'+name
                new_path = os.path.join(destination_path, new_name)
                # This is obviously going to fail because we just opened it
                shutil.move(path_to_zip_file, new_path)
        i += 1
        zfile.close()
    

    Changed some of the variable names in your code snippet. Do you see your problem now? You're trying to move the zip file that your process has open. You'll need to copy the .xls file to your destination using the zipfile module.

    0 讨论(0)
  • 2021-02-19 10:30

    If you are on a windows computer go to the task manager and hit the processes tab. Scroll down to anything that says python and end the process. You may have had python running with something else. Then try running your python program again and it should work.

    0 讨论(0)
提交回复
热议问题