I want to start off by saying, I'm well aware that this question has been asked plenty of times, across multiple Stack Exchange sites, but none of them have proven useful to me.
The questions in question:
Unix zipping sub directory not including parent directory
zip all files and subfolder in directory without parent directory (unix.stackexchange.com)
Zip an archive without including parent directory (askubuntu.com)
How to zip a directory without zipping the parents directories? [duplicate] (askubuntu.com)
I am currently writing a small script, which, if ran, zips a specified folder using wsl zip. The problem I am encountering, is the fact that if I use absolute paths to tell the command what to zip, it includes the whole path, instead of only starting at the last folder, the folder I actually want to zip.
Many of the questions that have been answered about this, suggest using cd or pushd before trying to zip, and ommit the absolute path from the zip command. However, that is where it fails in my case.
I am using the Windows Subsystem for Linux to access the zip command, but I am doing so from within the Windows console. The command in question I am using:
> wsl -e zip -r absolute/path/to/folder.zip absolute/path/to/folderBut this will result in a zip file structure as the following:
folder.zip absolute path to folder *While the result I am looking for is:
folder.zip folder *I tried to use the command cd, to ommit the absolute path from the zip command, but with no luck. Because I need to run the command from within the Windows console, opposed to in the WSL console, the following is not an option:
> wsl ~~$ cd absolute/path/toabsolute/path/to$ zip -r folder.zip folderInstead, I tried using a command like this:
> wsl -e "cd absolute/path/to && zip -r folder.zip folder"But that resulted in the following error:
<3>WSL (10963) ERROR: CreateProcessCommon:559: execvpe(cd) failed: No such file or directoryThe same error occurs, if I simplify the command to this:
> wsl cd absolute/path/toSo here's the question again, how can I ommit the full directory from the zip, when I cannot use cd or pushd?