Home > Mobile >  Avoid parent folder structure when creating tar
Avoid parent folder structure when creating tar

Time:10-11

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

I am using the compress method given in the above link for creating Tar with recursive folder structure in Golang.

Now, say if I give /home/Documents/project as src

Then, the created tar also contains /home/Documents/project/files I want to avoid the parent folder structure here.

Ex. tar should directly contain : files

How can I modify this method to achieve this ?

Thanks in advance.

CodePudding user response:

A tricky method without modifying the code, If your program does not have concurrent logic, you can do this:

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