首页 > 解决方案 > 创建 tar 时避免父文件夹结构

问题描述

https://github.com/mimoo/eureka/blob/master/folders.go

我正在使用上面链接中给出的压缩方法在 Golang 中创建具有递归文件夹结构的 Tar。

现在,说如果我给/home/Documents/project作为 src

然后,创建的 tar 还包含 /home/Documents/project/files 我想避免这里的父文件夹结构。

前任。tar 应直接包含:files

如何修改此方法以实现此目的?

提前致谢。

标签: gotardirectory-structure

解决方案


一个不修改代码的棘手方法,如果你的程序没有并发逻辑,你可以这样做:

os.Chdir("/home/Documents/project")
compress("./", output)

推荐阅读