How to create a zip file without entire directory structure

前端 未结 4 408
孤街浪徒
孤街浪徒 2021-01-04 00:58

I am trying to create a zip file and want to preserve most of the directory structure, but not the rootdir as defined from the command line. The command I\'m using is:

4条回答
  •  鱼传尺愫
    2021-01-04 01:48

    If someone stumbles upon this and is not satisfied with the above solution, here follows a very simple workaround to not zip long subdirectories. It involves temporarily creating a folder in C:/, and after zipping simply deleting it:

    ZipFiles <- list.files(".../ZipFiles") # Insert your long subdirectory into .../
    
    dir.create("C:/ZipFiles")
    dir.create(".../FolderToBeZipped")
    file.copy(from = ZipFiles,to = "C:/ZipFiles")
    zip(".../FolderToBeZipped",
        files = "C:/ZipFiles")
    unlink("C:/ZipFiles",recursive = TRUE)
    

    The result then is .../FolderToBeZipped.zip/ZipFiles/

    The benefit is that you need not be within the subdirectory (or project) when executing the code.

提交回复
热议问题