Need Help With A Bash Script For Working With Roms.


lancelott

Member
Joined
Dec 27, 2005
Messages
110
I'm trying to figure out how to make a bash script that would accomplish the following (starting from a GoodMerged set, where similar roms are 7zed together):

-`7za x` every 7z archive
-archive each rom file as a zip

I used to know how to iterate through files in bash, but no longer. If someone could figure out how to do this for me, it would be HIGHLY appreciated.
 
Well, I had a similar problem before. My friend wrote me a PHP script, since neither of us wanted to take the time to review bash again. You should have PHP installed already. If not, it may be rewritten in bash easily (not sure).
Code:
<?php
	$dir = ".";

	is_dir($dir) or die("{$dir} is not a dir...!\n");
	$dh = opendir($dir) or die("Could not open dir...\n");

	while(($file = readdir($dh)) !== false) {
		if($file != "." && $file != "..") {
			$zfile = explode(".", $file);
			array_pop($zfile);
			$zfile = implode(".", $zfile) . ".zip";
			system("zip \"{$zfile}\" \"{$file}\"");
		}
	}

	closedir($dh);
?>
That PHP script archives each rom (file) in the same directory as the script (not the current directory) as a separate archive. You should be able to adjust it to have the action be "7za d" instead of "zip". If not, let me know, and I'll adjust it myself.
 
Well I found out the first parts. I just need to figure out how to zip each individual file.

Code:
7za x -y "*.7z"
rm *.7z
for i in *; do 7za a -tzip $i.zip" "$i"; done

The last part works, I think, but the file extension is left on it. I want to remove the file extension (I'm trying first on .gen files). So it makes .gen.zip, I want .zip.
 
lancelott posted on May 2 2006 at 06:07 PM said:
Well I found out the first parts. I just need to figure out how to zip each individual file.

Code:
7za x -y "*.7z"
rm *.7z
for i in *; do 7za a -tzip $i.zip" "$i"; done

The last part works, I think, but the file extension is left on it. I want to remove the file extension (I'm trying first on .gen files). So it makes .gen.zip, I want .zip.
Well it's all the same, really. A .gen.zip file will have the same contents, and be read the same as a .zip file. But you can set up a regex or rename filter to work on each of the files after zipping.
 
Last edited by a moderator:
iignotus posted on May 2 2006 at 09:08 PM said:
lancelott posted on May 2 2006 at 06:07 PM said:
Well I found out the first parts. I just need to figure out how to zip each individual file.

Code:
7za x -y "*.7z"
rm *.7z
for i in *; do 7za a -tzip $i.zip" "$i"; done

The last part works, I think, but the file extension is left on it. I want to remove the file extension (I'm trying first on .gen files). So it makes .gen.zip, I want .zip.
Well it's all the same, really. A .gen.zip file will have the same contents, and be read the same as a .zip file. But you can set up a regex or rename filter to work on each of the files after zipping.
How would I do that? I'm really nitpicky, and even though it would technically work, it bugs me too much.
 
Last edited by a moderator:
lancelott posted on May 2 2006 at 06:07 PM said:
Well I found out the first parts. I just need to figure out how to zip each individual file.

Code:
7za x -y "*.7z"
rm *.7z
for i in *; do 7za a -tzip $i.zip" "$i"; done

The last part works, I think, but the file extension is left on it. I want to remove the file extension (I'm trying first on .gen files). So it makes .gen.zip, I want .zip.
the following script should rename all ".gen.zip" files to ".zip" in the current directory.
Code:
#!/bin/sh

files=`ls *.gen.zip`

for i in $files
do
  newname=`echo $i | sed s/.gen//g`
  `mv $i $newname`
done
 
Last edited by a moderator:
Back
Top