Jump to content

Useful Windows Batch Files to zip up Roms and rename tasks


azzajess

Recommended Posts

Hey everyone, I have assembled some useful Windows Batch Files to help with the automatic zipping for roms and other tasks.

To create the .bat file simply create a text document within Windows and name it what you would like and make sure the extension is .bat
Then you want to right click and press 'edit' in order to add text to the document. Simply copy and paste one of the following code and save it.
By default windows doesnt normally allow you to see extensions of known file types so you may have to do a quick Google Search on how to show file extensions on all files

If you would like to change the compression type to either 7z or zip, simply replace the extension where it says either .7z or .zip to the compression type you want.

Some of these file can/may be improved, as these arnt perfect, however they may help you like they have helped me.

NOTES
You must have 7z installed on the computer. I have included the default directory to 7z however double check your directory to make sure its in the same place, otherwise change it to the correct directory
All Batch files should be in the same directory you would like the operation, this means the .bat files are portable. So sometimes the Batch file may also be ziped up ?

-----

BatchFolder2zip.bat

The below code automatically zips the files inside folders with the folders name. This is useful for zipping up Foldered roms but dont want to zip up the folder as well. This is useful for SkumVM if you wanted to convert your folder rom set to ZIP

for /d %%X in (*) do "C:\Program Files (x86)\7-Zip\7z.exe" a "%%X.zip" "./%%X/*"

Pseudo Code: For content inside every folder for any extension run 7z and add the contents inside folder and name the zip the same as the folder.

---------------------

BatchFile27z.bat

This automatically zips all files within the same directory of the batch file into a 7z. Useful for making NES or snes roms into 7z, or pretty much any standalone rom

FOR %%i IN (*.*) DO "C:\Program Files (x86)\7-Zip\7z.exe" a "%%~ni.7z" "%%i"

Pseudo Code: For the name of every file with any extension use 7z.exe to create a zip with the current name minus extension.

-------------------

BatchFilesInFolder27z.bat

So what this does is it puts all the files inside multiple folders in the current directory into a 7z file outside the folder. HOWEVER it only zips the files within the folder if they have the same name but can have different extentions. For example Folder name is Crash_Bandicoot and inside the folder is Crash Bandicoot (USA).bin and Crash Bandicoot (USA).cue. The batch file will automatically zip both files inside the folder (because they have the same name) and place the zip outside that folder called Crash Bandicoot (USA).7z. Just keep in mind, this will also automatically zip any other file with a different name in its own zip such as track01.bin files. etc

FOR /r %%i IN (*) DO "C:\Program Files (x86)\7-Zip\7z.exe" a "%%~ni.7z" "%%i"

Pseudo Code: For files inside directory with any extension use 7z to add files to 7z with name INSIDE folder pairing it up with files of the same name

------------------

BatchFile2Folder2Manual.bat

For every PDF/anyfile [Replace(*.pdf*) with (*.*) or for text files (*.txt*)] file, it will create a folder of the same name and then rename the file to Manual.pdf. It will then move that file into the folder.
This is useful for Manuals downloaded from EmuMovies Download Service as it downlaods the manual as the name of the game and to follow the structure of RocketLaunch, its normally in games name folder.

FOR %%i IN (*.pdf*) DO md "%%~ni" & ren "%%i" Manual.pdf & move Manual.pdf "%%~ni" 

Pseudo Code: For every file name that ends with .pdf, create a folder with the PDF file name without .pdf and rename the pdf file to Manual.pdf then move the file into the folder just created.

------------------

RenameFolderBasedOffFileName.bat

This simply renames the folder based off the file name of whats inside the folder. Im not entirely sure the affect this has on multiple files within the folder so please try in a separate area before use

  1. for /d %%a in (*) do (
  2.   for %%b in ("%%a\*.*") do (
  3.     ren "%%a" "%%~nb"
  4.   )
  5. )

------------------

RenameFilesInFolder2FolderName.bat

This basically renames the files within the folder with the name of the folder. It specifically looks for iso/bins/cue and renames them based off the folder name. This is a dirty and is slower in performance however it does get the job done. If you wanted different file extensions, just change the the bin/cue/iso to another file extension. You can remove or add lines if necessary. This may cause conflict if you have more than one file in the folder with the same extension, however shouldn't matter if they are different extensions (bin/cue).  Please try this in a separate area before using it in your main folders. 

  1. for /r %%F in (*.bin) do @for %%A in ("%%F\..") do ren "%%F" "%%~nxA.bin"
  2. for /r %%F in (*.iso) do @for %%A in ("%%F\..") do ren "%%F" "%%~nxA.iso"
  3. for /r %%F in (*.cue) do @for %%A in ("%%F\..") do ren "%%F" "%%~nxA.cue"

------------------

I am aware that there may be other utilities that can do the same thing such as Dons Rom Rename however these batch files may have other use cases and I am only sharing them because I found them useful, and it may help others as well. 

I would recommend that you test it on a smaller batch to test it out before converting your entire rom library

TIP: If you would like to see the progress when it finishes or want to debug it, Press enter at the end of the line and add      PAUSE         under the code

If you have any useful batch files or improvements to the ones here, dont hesitate to share them.

Cheers

Link to comment
Share on other sites

  • 1 month later...

I wanted to say thank you for these valuable scripts and for saving me a ton of time with my Sega Saturn roms.  I had a single folder full of bin cue files and your batch file made quick work out of it.
Now I have a folder full of 7z files - right where I wanted to end up.

Thank you!

Link to comment
Share on other sites

10 hours ago, Sncboom2k said:

I wanted to say thank you for these valuable scripts and for saving me a ton of time with my Sega Saturn roms.  I had a single folder full of bin cue files and your batch file made quick work out of it.
Now I have a folder full of 7z files - right where I wanted to end up.

Thank you!

My pleasure. I'm glad these scripts helped.

Link to comment
Share on other sites

This is great, I will save this post and work with some of them. Sometimes I find annoying tasks, like organizing my collection and then I think, "If I had a batch to do this, or if I knew how to make one". 

This is so helpful. Many thanks man

Link to comment
Share on other sites

Hi,

Just came up with a situation. Do any of you guys have a batch to rename a .7z file to match its internal file?

For example, I will use this scenario:

Crash Bandicot PSX.7z

----Crash Bandicot (USA).iso

----Crash Bandicot (USA).cue

 

I I'd like to rename the .7z name to match the .cue file (preferably). Like this:

Crash Bandicot (USA).7z

----Crash Bandicot (USA).iso

----Crash Bandicot (USA).cue

 

I Assume the .cue file is fine and matching the image. So no need to touch it.

Thanks

Link to comment
Share on other sites

6 hours ago, badboo said:

Just came up with a situation. Do any of you guys have a batch to rename a .7z file to match its internal file?

Crash Bandicot PSX.7z

----Crash Bandicot (USA).iso

----Crash Bandicot (USA).cue

I I'd like to rename the .7z name to match the .cue file (preferably). Like this:

Crash Bandicot (USA).7z

----Crash Bandicot (USA).iso

----Crash Bandicot (USA).cue

Hey, I don't think a batch file is able to rename based what's inside a zip without extracting it. There is however a neato program that can rename all sorts based off a database, including just naming zips/files or the files inside and then rezipping. The program is also able to rename the data inside the cue file. Anyway the software is

http://www.hyperspin-fe.com/files/category/446-romdatabaserenaming-tools/

Link to comment
Share on other sites

Hey, I don't think a batch file is able to rename based what's inside a zip without extracting it. There is however a neato program that can rename all sorts based off a database, including just naming zips/files or the files inside and then rezipping. The program is also able to rename the data inside the cue file. Anyway the software is
http://www.hyperspin-fe.com/files/category/446-romdatabaserenaming-tools/

Oh I see, in that case I will give that tool a try. Maybe this tool will help me with my issue. Thanks for your reply

Sent from my SM-G900W8 using Tapatalk

Link to comment
Share on other sites

On 1/19/2017 at 10:04 PM, azzajess said:

-------------------

BatchFilesInFolder27z.bat

So what this does is it puts all the files inside multiple folders in the current directory into a 7z file outside the folder. HOWEVER it only zips the files within the folder if they have the same name but can have different extentions. For example Folder name is Crash_Bandicoot and inside the folder is Crash Bandicoot (USA).bin and Crash Bandicoot (USA).cue. The batch file will automatically zip both files inside the folder (because they have the same name) and place the zip outside that folder called Crash Bandicoot (USA).7z. Just keep in mind, this will also automatically zip any other file with a different name in its own zip such as track01.bin files. etc


FOR /r %%i IN (*) DO "C:\Program Files (x86)\7-Zip\7z.exe" a "%%~ni.7z" "%%i"

Pseudo Code: For files inside directory with any extension use 7z to add files to 7z with name INSIDE folder pairing it up with files of the same name

 

Hi,

I would like to do something similar to this. But how can I make, at the moment to 7z the folder to match the .cue file and take all the files inside, instead of separating them?

 

Edit: No worries, I managed to do this ;)

Link to comment
Share on other sites

On 04/03/2017 at 1:08 PM, badboo said:

...how can I make, at the moment to 7z the folder to match the .cue file and take all the files inside, instead of separating them? 

Edit: No worries, I managed to do this ;)

Hey, sorry for the late reply, but did you create a new bat script to do the operation you wanted? If so feel free to share it :)

Link to comment
Share on other sites

19 minutes ago, azzajess said:

Hey, sorry for the late reply, but did you create a new bat script to do the operation you wanted? If so feel free to share it :)

Hey no worries, actually I couldn't find anything related to what I was looking for and I had to do it manually :(

That is why I mentioned that I managed to this, because I went the "one by one" way lol

But I will leave a link to this other contribution that was made by a member of this forum (@ci2own), and it has helped me out too. Here is the link:

Batch compress files inside folders

Link to comment
Share on other sites

I am back again. I am in another situation lol.

So, this media for hyperpause. It is a lot of content by the way, like 350 gb. (for reference, you guys can go to youtube and search retrohumanoid. I didn't post the link because he has his reason not to, but you guys can go and find his channel. It is worth it).  But would only need a batch for the manuals section.

So I got a lot of manuals, hundred of them. They are in JPG. So I'd like to PDF all of them, because the pause takes a while to load all of these media, and maybe it is easy for it to read from a single PDF than hundred of pages in JPG.

Ok, so the structure goes like this: 

I have the folder "_Default", and in it are other folders with the name of the magazines, and in each folder are the JPG's. 

i.e.:

_Default/nintendo 12-1995/01.jpg

                                               02.jpg

                                                03.jpg

_Default/nintendo 12-1996/01.jpg

                                               02.jpg

                                                03.jpg

............and so on.

So, is there a way to have a batch and place it in the _default folder and pdf all these JPG's inside the subfolders and create the PDF with the name of the subfolder?

Thanks in advance.

Link to comment
Share on other sites

19 hours ago, badboo said:

So, is there a way to have a batch and place it in the _default folder and pdf all these JPG's inside the subfolders and create the PDF with the name of the subfolder?

Thanks in advance.

I don't think there is a way to do it via command line since it relies on a program to do some of the automating. In my case I was using 7z.exe which had particular parameters I could use. For your case the program would also need to support this if I'm correct. What program that is, I'm unsure. 

With that said there may be a program with a graphical interface that may allow you to batch convert your jpgs based off using the folders name. 

I would imagine that there is a program for doing this, it's a matter of finding it. Ill have a better look tomorrow for ya. 

Link to comment
Share on other sites

3 hours ago, azzajess said:

I don't think there is a way to do it via command line since it relies on a program to do some of the automating. In my case I was using 7z.exe which had particular parameters I could use. For your case the program would also need to support this if I'm correct. What program that is, I'm unsure. 

With that said there may be a program with a graphical interface that may allow you to batch convert your jpgs based off using the folders name. 

I would imagine that there is a program for doing this, it's a matter of finding it. Ill have a better look tomorrow for ya. 

Oh, then that is why I couldn't find anything like that. I spent a couple of hours or more looking for that, and nothing.

I downloaded a few programs also, but I can only go folder by folder. Which I rather go with the acrobat version that I have, because gives better quality.

The only thing close that I found, was in a forum where a guy there had the tool for that but he was charging $80 to everyone who was asking the same question as me. I rather do it folder by folder than paying $80.

Thanks for looking into that.

Link to comment
Share on other sites

On 14/03/2017 at 11:09 PM, badboo said:

Oh, then that is why I couldn't find anything like that. I spent a couple of hours or more looking for that, and nothing.

I downloaded a few programs also, but I can only go folder by folder. Which I rather go with the acrobat version that I have, because gives better quality.

The only thing close that I found, was in a forum where a guy there had the tool for that but he was charging $80 to everyone who was asking the same question as me. I rather do it folder by folder than paying $80.

Thanks for looking into that.

Perhaps we can have a two step method, first step is batch converting all the files in a folder to one pdf with any file name then setup a batch file that goes in and renames the files in all the folders with the folders name.

That is doable,  I believe so if we can figure out a batch convert so it converts the jpgs to a single pdf in a bunch of folders then we can do a rename script... 

Just a matter of finding a decent one. 

Link to comment
Share on other sites

9 hours ago, azzajess said:

Perhaps we can have a two step method, first step is batch converting all the files in a folder to one pdf with any file name then setup a batch file that goes in and renames the files in all the folders with the folders name.

That is doable,  I believe so if we can figure out a batch convert so it converts the jpgs to a single pdf in a bunch of folders then we can do a rename script... 

Just a matter of finding a decent one. 

That way of thinking sounds good. I am gonna do a research on that.

If a find this work around, then I will post it here.

Link to comment
Share on other sites

On 1/20/2017 at 3:04 AM, azzajess said:

FOR %%i IN (*.*) DO "C:\Program Files (x86)\7-Zip\7z.exe" a "%%~ni.7z" "%%i"

I cant get this one to work @azzajess

EDIT: it's fine. Think I had it with single % symbols for some reason

folder structure

TEST

      --test1.txt

      --test2.txt

      --batchfile27z.bat

 

This one works but includes the extention in the new zip or 7z

 

 for %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\"

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...