如何避免找不到文件(WinError 3)?

How to avoid files that are not found (WinError 3)?

我试图将我的整个计算机驱动器备份到 google 云存储,人们主要告诉我那是荒谬的,在思考这一切时,我决定只做文档和桌面,我的目标是使用 google 云 SDK,因为我是新手,我喜欢挑战。所以我输入:

gsutil -m rsync -n -J -C -e -r -u -U C:\Users\~~~~\Documents gs://~~~~-pc/documents

当我发送它时,我收到了这条消息:

Caught non-retryable exception while listing file://C:\Users~~~~~\Documents: [WinError 3] The system cannot find the path specified: 'C:\Users\~~~~~\Documents\~~~~~~~~~ Files15 NEGOTIATIONIS05 NEGOTIATIONS FILE - MAIN\Implementation\Temporary Transfers and Permanet Involuntary Force Rearragement\Temporary Transfers and Permanent Involuntary Force Rearrangement FINAL October 3 2014.docx' CommandException: Caught non-retryable exception - aborting rsync

请帮忙!!!

注:“~”为审查

编辑:我进行了调试,但我不知道这是什么意思,这里的输出没有显示我的个人数据:

Caught non-retryable exception while listing file://C:\Users\~~~~\Documents: [WinError 3] The system cannot find the path specified: 'C:\Users\~~~~\Documents\~~~~ Files\2015 NEGOTIATIONIS\2105 NEGOTIATIONS FILE - MAIN\Implementation\Temporary Transfers and Permanet Involuntary Force Rearragement\Temporary Transfers and Permanent Involuntary Force Rearrangement FINAL October 3 2014.docx'
Traceback (most recent call last):
  File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gslib\commands\rsync.py", line 653, in _ListUrlRootFunc
    out_file)
  File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gslib\commands\rsync.py", line 903, in _BatchSort
    current_chunk = sorted(islice(in_iter, buffer_size))
  File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gslib\commands\rsync.py", line 734, in _FieldedListingIterator
    for blr in iterator:
  File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gslib\wildcard_iterator.py", line 701, in IterObjects
    bucket_listing_fields=bucket_listing_fields):
  File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gslib\wildcard_iterator.py", line 721, in IterAll
    bucket_listing_fields=bucket_listing_fields):
  File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gslib\wildcard_iterator.py", line 611, in __iter__
    blr_object = _GetFileObject(filepath) if include_size else None
  File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gslib\wildcard_iterator.py", line 531, in _GetFileObject
    return apitools_messages.Object(size=os.path.getsize(filepath))
  File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\bundledpython\lib\genericpath.py", line 50, in getsize
    return os.stat(filename).st_size
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\Users\~~~~\Documents\~~~~ Files\2015 NEGOTIATIONIS\2105 NEGOTIATIONS FILE - MAIN\Implementation\Temporary Transfers and Permanet Involuntary Force Rearragement\Temporary Transfers and Permanent Involuntary Force Rearrangement FINAL October 3 2014.docx'

DEBUG: Exception stack trace:
    Traceback (most recent call last):
      File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gslib\__main__.py", line 634, in _RunNamedCommandAndHandleExceptions
        user_project=user_project)
      File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gslib\command_runner.py", line 411, in RunNamedCommand
        return_code = command_inst.RunCommand()
      File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gslib\commands\rsync.py", line 1657, in RunCommand
        diff_iterator = _DiffIterator(self, src_url, dst_url)
      File "C:\Users\~~~~\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gslib\commands\rsync.py", line 999, in __init__
        raise CommandException('Caught non-retryable exception - aborting rsync')
    gslib.exception.CommandException: CommandException: Caught non-retryable exception - aborting rsync

您的问题是由 MAX_PATH 引起的。默认为 260 个字符。

方法 1 - 指定 UNC 路径

路径前缀为 "\?\"。这会将最大路径名更改为 32,767 个字符。

\?\C:\Users\~~~~\Documents

方法 2 - 更改 Windows 注册表

要解决您的问题,需要编辑注册表以支持最长 32,767 个字符的更长路径名。

更改此注册表项:

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled
Type: REG_DWORD
Value: 1

阅读此文档以获取更多信息:

Enable Long Paths in Windows 10, Version 1607, and Later