解压时遇IsADirectoryError:如何将目标目录内容导出至其他位置?
Hey there! That error makes total sense—you were trying to use Python's zipfile module (which is for working with compressed zip archives) on a directory instead of a zip file. No worries though, moving the contents of that directory to your target location is straightforward.
Here are two reliable ways to do it:
1. Python Cross-Platform Method
Use the shutil and os modules—they’re built into Python and work on Windows, macOS, and Linux. This code will copy every file and subdirectory from your source directory into the target location:
import os import shutil # Define your source and target paths source_dir = "mask-rcnn-resnet50-ver-01.a" target_dir = "../output/0180306/build" # Make sure the target directory exists (create it if not) os.makedirs(target_dir, exist_ok=True) # Iterate over every item in the source directory for item_name in os.listdir(source_dir): source_path = os.path.join(source_dir, item_name) target_path = os.path.join(target_dir, item_name) if os.path.isdir(source_path): # Copy subdirectories recursively (overwrites existing if needed) shutil.copytree(source_path, target_path, dirs_exist_ok=True) else: # Copy individual files (preserves metadata like creation time) shutil.copy2(source_path, target_path)
2. Shell Command (Linux/macOS Only)
If you’re working in a Unix-like environment, a simple shell command will do the trick in one line:
cp -r mask-rcnn-resnet50-ver-01.a/* ../output/0180306/build/
The -r flag tells cp to copy recursively (including subdirectories), and the * ensures we copy all contents of the source directory (not the directory itself) into the target.
Just remember: forget using zipfile on this path—it’s a directory, not a zip archive, so that module won’t work here.
内容的提问来源于stack exchange,提问作者Green

