Hello everyone - just scratching my head and cannot find a proper solution…
I have got a zip file that includes many files with a / inside the file name,
e.g. foo [comment1 / comment2].txt. When i unzip it creates the folder
foo [comment1 and inside that folder there is comment2].txt
so now i get many folders with files inside that needs to be renamed to the original name. I tried unzip -j which only eliminates the folder structure but the filenames are still messed up. Some files even got several / in their names as separator which makes it even worst. There are too many to manually do the work. And as well there must be a solution to keep the / inside the file name instead of the Linux subdirectory separator.
I use EXT4 but the zip files are stored on a Windows network at work. No chance to change the file names on the Windows side as they are automatically exported from another program. So the .zip file which includes these files is given.
Now I need to find a way how I can extract it reasonably to my Endeavour system at home to keep working on them. And yes, the Linux system does exactly what it should when recognizing /.
Maybe during the unzip operation the / could be changed into a &. As those files don’t go back into the system at work the separator symbol doesn’t matter really but for the analysis I need the full information that unfortunately is given by the file name that now splits up into different folders. I am not good at shell and pipes so would have no idea how to make it.
Do the zip files have actual sub-directories in them? If they don’t, it would be trivial to write a script that fixed the filenames and pulled them out of the directories after extraction.
If not, you would have to do something like I posted in the link above.
find . -mindepth 2 -type f | while read file; do new_file=$(echo "${file}" | sed 's,/,_,g' | sed 's,^\._,,'); mv "${file}" "./${new_file}"; done
@OsZ when you run the above code form the top-most directory of your extracted filed it should bring every file there and rename all / to _ (the chatacter _ is defined in sed sequences).
Be careful I did not test it thoroughly. You can test the output first by for example replacing mv "${file}" "./${new_file}"
with echo "${file}"; echo "./${new_file}"
So it looks like
find . -mindepth 2 -type f | while read file; do new_file=$(echo "${file}" | sed 's,/,_,g' | sed 's,^\._,,'); echo "${file}"; echo "${new_file}"; done
All you have to do after that is to delete all folders (they should be empty).
Sadly I don’t think you can have / in file’s name.
May I ask why is it so important to have / as a part of the file’s name?
If you want to reference to the file from some application then foo/bar.txt expects bar.txt file inside foo directory. Therefore what happened at first is the correct state (even though it may look like a mess).
I know some industrial PLC systems do not have a directory structure - everything is in one directory. Then someone may have a tendency to use / as a valid character. In this case I would expect you would implement download/upload sequence which would replace slash character with some valid-not-so-common character (like = for instance) when you download the file and turn them all back when you upload it.