Compressing only files using 7z without preserving the path

前端 未结 5 673
梦谈多话
梦谈多话 2021-02-03 18:57

I am using 7z command line executable to zip files, but I see that while adding to an archive the path of the files is preserved in the archive.

So if I do



        
5条回答
  •  醉梦人生
    2021-02-03 19:35

    As explained in related question in 7-zip user FAQ, 7z stores paths relative to working directory, so you will need to first cd to desired top-level directory for archive and run 7-zip from here.

    cd dir1\dir2\
    7z a -tzip  myzip.zip *
    

    If you run it from script and don't want to affect it with changed directory, use directory push/pop facilities available in your shell of choice or run cd+7-zip in spawned process to avoid affecting your entire script with changed directory. For example, using Windows' start that would be:

    start /D dir1\dir2\ /wait 7z a -tzip  myzip.zip *
    

提交回复
热议问题