Reputation: 145
I have a zip file with this structure:
Report
│
└───folder1
│ │
│ └───subfolder1
| |
│ │file 1 2022.txt
│
└───folder2
│ file2.txt
And their relative file paths are as follows: Report/folder1 / subfolder1 / file 1 2022.txt
and Report/folder2/file2.txt
I tried to extract the zip file to another destination using the following code:
with ZipFile(attachment_filepath, 'r') as z:
z.extractall('Destination')
However, it gives me a FileNotFoundError: [Winerror 3] The system cannot find the path specified: 'C:\\Users\\myname\\Desktop\\Report\\folder1 \\ subfolder1 '
I can extract just file2.txt
without any problems but trying to extract file 1 2022.txt
gives me that error,presumably due to all the extra whitespaces
Upvotes: 1
Views: 189
Reputation: 77347
"folder1 "
(note the space) isn't the same as "folder1"
(no space). When passing a path, it has to be the exact path. You can't add whitespace between path separators because the file system will assume you want a path name with spaces. Whatever put those spaces into the path is the problem.
Upvotes: 1