[Unzip] How to decompress only arbitrary files from those whose directory delimiter in the zip file is backslash

It may be obvious, but I couldn't find the answer even if I looked it up in the feeling, so I'll write it down for the purpose of reminders.

What happened

When you want to decompress only a specific file with the unzip command

If you have a zip file like the one below

hoge.zip


$ zipinfo -1 hoge.zip
aaa/bbb/ccc.txt
ddd/eee/fff.jpg
ggg/hhh/iii.log

This can be achieved with unzip {zip to be decompressed} {file path you want to extract}.

$ unzip hoge.zip aaa/bbb/ccc.txt

But if the directory delimiter in the zip file was a backslash

hoge_bs.zip


$ zipinfo -1 hoge_bs.zip
aaa\bbb\ccc.txt
ddd\eee\fff.jpg
ggg\hhh\iii.log

If you enter the command in the same way, an error will occur.

$ unzip hoge_bs.zip aaa\bbb\ccc.txt
Archive:  hoge_bs.zip
caution: filename not matched:  aaabbbccc.txt

trial and error

Should I enclose it in single quotes? I think this is also useless

$ unzip hoge_bs.zip 'aaa\bbb\ccc.txt'
Archive:  hoge_bs.zip
caution: filename not matched:  aaa\bbb\ccc.txt

Is the path actually converted to a slash when expanded? I tried it, but this is also useless

$ unzip hoge_bs.zip 'aaa/bbb/ccc.txt'
Archive:  hoge_bs.zip
caution: filename not matched:  aaa/bbb/ccc.txt

How it worked

It worked well when I gave it two backslashes

$ unzip hoge_bs.zip 'aaa\\bbb\\ccc.txt'
Archive:  hoge_bs.zip
warning:  hoge_bs.zip appears to use backslashes as path separators
  inflating: aaa/bbb/ccc.txt

When I put it together like this, I'm starting to regret that this is common sense ...

Recommended Posts

[Unzip] How to decompress only arbitrary files from those whose directory delimiter in the zip file is backslash
How to get a list of files in the same directory with python
Extract only the file name excluding the directory in the directory
Unzip all zip files under the current directory
How to list files under the specified directory in a list (multiple conditions / subdirectory search)
How to know the current directory in Python in Blender
How to download files from Selenium in Python in Chrome
How to change static directory from default in Flask
How to log in automatically like 1Password from the CLI
How to deal with the problem that the current directory moves when Python is executed from Atom
Unzip the internet zip file
How to give and what the constraints option in scipy.optimize.minimize is
How to judge that the cross key is input in Python3
How to use the asterisk (*) in Python. Maybe this is all? ..
Save the Pydrive authentication file in a different directory from the script
[Ln] How to paste a symbolic link in a directory is complicated
[Python] What to do when PEP8 is violated in the process of importing from the directory added to sys.path