Unzip the files and rename with zip file name? - rename

I need to unzip files using 7zip and rename the unzipped files.
Assume that the zip file is 3457.zip and it is contains w.dat and q.doc. I'd like to rename w.dat and q.doc to 3457.dat and 3457.doc.
How can this be achieved using a bat file?

Related

unziping files in linux folder

in Python I have the following command executed unzip '{dir}ATTOM_RECORDER/*.zip' -d {dir}ATTOM_RECORDER/ as a bash command. The python call works perfectly. my question is about the unzip command itself.
for some reason when unzip is called to expand any relevent zip files in the folder specified, not all the files WITHIN the zip is extracted. There's usually a rpt and a txt file. However, sometimes the txt file is not coming out and I do not have an error command.
How can I ensure the txt file is guaranteed to be extracted before moving on?
Thanks
While you want to unzip your specific zip file. There are many option to decompress any file from zip files. Easiest way is the ā€˜-lā€™ option with unzip command is used to list the contents of a zip file after extracting it.
Syntax: unzip -l [file_name.zip]

How to get the list of files (ls command) from bz2 archive?

What is the Unix bash command to get the list of files (like ls) from archive file of type .bz2 (without unzipping the archive)?
First bzip2, gzip, etc compress only one file. So probably you have compressed tar file. To list the files you need command like:
tar tjvf file.bz2
This command uncompress the archive and test the content of tar.
Note that bzip2 compresses each file, and a simple .bz2 file always contains a single file of the same name with the ".bz2" part stripped off. When using bzip2 to compress a file, there is no option to specify a different name, the original name is used and .bz2 appended. So there are no files, only 1 file. If that file is a tar archive, it can contain many files, and the whole contents of the .tar.bz2 file can be listed with "tar tf file.tar.bz2" without unpacking the archive.

unzip in current directory while preserving file structure

I'm in a directory and I have a zip containing files and directories.
I need to unzip that file, into current directory, but preserving the file structure.
unzip myfile.zip will create a myfile directory in current directory which is not what I want.
unzip -j myfile.zip will kill all the file strucure, which is not what I want.
unzip myfile.zip extracts files in the working directory by keeping path names from the zip file.
So if you get a subdirectory myfile it means it is part of the relative path of compressed files. Check it by listing the zip content
unzip -l myfile.zip
So you can unzip the file from the directory above, or, from the target directory unzip with -d option, where -d is the directory above
cd myfile
unzip myfile.zip -d ..
Dont select the folder while zipping.
For example
myfile/abc.txt and myfile/efg.txt
so while zipping select the files (abc.txt,efg.txt) and zip dont select the myfile folder to zip.
So that when you unzip the file, the parent dir for each file or folder will be the directory in which you unzip.
The myfile directory was zipped into the zip file when it was created and looking at the unzip options there isn't a way to do this without adding additional steps.
If this entire process is under your control you should look at either creating the zip without using including the parent directory or you could use an alternative like tar (to create and extract) which allows you to extract content from the repo with greater precision.

How to rename files according to other files?

I have several files in a folder with extension .img and I have only one file with extension data.txt
What I need is to copy data.txt and rename it as the names of the .img files.
For instance for the first file in my folder:
`Meaurmen_2154_data.img` >>> copy data.txt >>> rename it Meaurmen_2154_data.txt
Now I have :
Meaurmen_2154_data.img
Meaurmen_2154_data.txt ## the content is the same as data.txt
and do the same for all other files. The content of he text files will be the same for all files just we change the name according to the .img files in my folder.
Run this script
#!/bin/bash
imageFiles=( *.img );
for i in ${imageFiles[*]}
do
withoutExtension=${i%.img};
cp data.txt "$withoutExtension.txt";
done
inside the relevant directory and it will do it for you.
Try
for i in *.img; do cp data.txt $i.txt; done
rename 's/.img.txt/.txt/' *.img.txt
In some distro's rename is different, requiring
rename .img.txt .txt *.img.txt
As always, you might find yourself in need of installing additional packages.

Can we add files to a zip archive with modified file names

I want to create a zip archive for some files in folder hierarchy.
for example:
abc.php_0973_890
newone.text_2344_870
I want to have:
abc.phpnewone.txt in my zip archive. Is there any way for doing this?
We can not do that as zip doesnot suuport anything like that, we can use tar for such things as it as options like: --transform which can be used to transform the output filename

Resources