fix: 修复文件复制函数中的目标目录创建逻辑,确保目录存在
This commit is contained in:
1 parent
6a2d5b3445
commit
5d5049805d
2 files changed
+6
-1
No files matched your search
@@ -16,6 +16,11 @@ func CopyFile(localPath, newPath string) error {
|
||||
}
|
||||
defer srcFile.Close()
|
||||
|
||||
// 如果目标目录不存在,创建它
|
||||
if err := os.MkdirAll(filepath.Dir(newPath), os.ModePerm); err != nil {
|
||||
return fmt.Errorf("failed to create destination directory: %v", err)
|
||||
}
|
||||
|
||||
// 创建目标文件
|
||||
dstFile, err := os.Create(newPath)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user