试图重命名OneDrive的文件时许可

发布于 2025-02-08 08:35:52 字数 1832 浏览 1 评论 0原文

当我运行加密文件的代码时,我会收到以下错误:

<_io.TextIOWrapper name='C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 >(2).png' mode='r' encoding='cp1252'>
read
encrypting
encrypted
encrypted file saved
Traceback (most recent call last):
  File "c:\Users\depen\OneDrive\Documents\python\timer\encrypt.py", line 93, in <module>
    encrypt(fpath)
  File "c:\Users\depen\OneDrive\Documents\python\timer\encrypt.py", line 67, in encrypt
    os.rename(file_fpath, file_fpath + ".encrypted")
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png' -> 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png.encrypted'

以下是我的代码:

fernet = AES(key)

def encrypt(file_path):
    #start a timer
    start = time.time()

    def read_in_chunks(file_object, chunk_size= 52428800):
        while True:
            data = file_object.read(chunk_size)
            if not data:
                break
            yield data


    with open(file_path, "rb") as f:
        for piece in read_in_chunks(f):
            data = fernet.encrypt(randbytes(16), piece, randbytes(16))
            currenttime = time.time()
            print(currenttime - start)
            with open (file_path + ".enc", "ab") as f:
                f.write(data)
                f.close()
    
    with open("filenames.txt", "a") as file:
        file.write(file_path + "\n")
        file.close()
    #end the timer
    end = time.time()
    print ("Time taken to encrypt   `: " + str(end - start))
    os.remove(file_path)

代码确实加密文件,但剂量不添加。将.centpypted添加到文件名的末尾。

When I run my code that encrypts a file, I get the following error:

<_io.TextIOWrapper name='C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 >(2).png' mode='r' encoding='cp1252'>
read
encrypting
encrypted
encrypted file saved
Traceback (most recent call last):
  File "c:\Users\depen\OneDrive\Documents\python\timer\encrypt.py", line 93, in <module>
    encrypt(fpath)
  File "c:\Users\depen\OneDrive\Documents\python\timer\encrypt.py", line 67, in encrypt
    os.rename(file_fpath, file_fpath + ".encrypted")
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png' -> 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png.encrypted'

Here is my code:

fernet = AES(key)

def encrypt(file_path):
    #start a timer
    start = time.time()

    def read_in_chunks(file_object, chunk_size= 52428800):
        while True:
            data = file_object.read(chunk_size)
            if not data:
                break
            yield data


    with open(file_path, "rb") as f:
        for piece in read_in_chunks(f):
            data = fernet.encrypt(randbytes(16), piece, randbytes(16))
            currenttime = time.time()
            print(currenttime - start)
            with open (file_path + ".enc", "ab") as f:
                f.write(data)
                f.close()
    
    with open("filenames.txt", "a") as file:
        file.write(file_path + "\n")
        file.close()
    #end the timer
    end = time.time()
    print ("Time taken to encrypt   `: " + str(end - start))
    os.remove(file_path)

The code does encrypt the file but dose not add a .encrypted to the end of the filename.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霓裳挽歌倾城醉 2025-02-15 08:35:52

您会遇到此错误,因为您正在使用OneDrive目录。 OneDrive正在尝试同步文件,因此创建文件后,他将尝试上传文件。

尝试从OneDrive不使用的另一个目录执行您的代码

The process cannot access the file because it is being used by another process: 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png' -> 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png.encrypted'

You got this error because you are working on onedrive directory . Onedrive is trying to sync the file so once you create the file , he's trying to upload the file.

Try to execute your code from another directory that onedrive is not using

The process cannot access the file because it is being used by another process: 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png' -> 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png.encrypted'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文