I have a zip which contains files with very long names.
If I try to extract on the command line, I get the error "File name too long".
If I use the graphical archive manager it will not extract the files and it will not let me rename them. The same problem occurs if I mount the archive.
I can extract and rename files individually using:
unzip -p -c example.zip "long file name.ogg" > shortname.ogg
This is impractical with lots of files.
Is there a tool which will truncate filenames as they are extracted?
Best Answer
To extract
We can use
zipinfo
as a part of this process, it's a program fromzip
package.will only shows the files names in
example.zip
, something look like:so we can use this feature to extract all files:
long_fname=${i%.*}
: Removes extension from long file name, so in case of file name being less that of 256 character; We're not going to get a duplicate extension.${long_fname:0:250}.${i##*.}
: Creates a new file name with legitimate number of character also adds a.
and file real extension.Simply we are looping into files list and extract each of them with a new legitimate file name which is 256 character.
To rename
You can use
zipnote
command, it's a part ofzip
package too.Get a backup of your zip file first.
Run this command:
Open names using an editor, it's look like this:
Add new file names like this:
Then to rename files use:
You renamed them all, you can also write a simple script which do this automatically for you.