I am a newbie!!!!!!!!!!!! This code is pieces of other peoples code.
First a run down of what it does. Basically its a batch renamer.
I assume a iso didn't match the list, but it closes to soon to see. Instead of continuing to the next iso it just stops. Also It has occasionally only half completed a couple.
Any help would be appreciated.
First a run down of what it does. Basically its a batch renamer.
- Verifies iso file is a valid game from wiitdb database via wiitdb.txt
- Copies iso files from current directory and subdirectories to "games" folder. In a 1:1 way. No compression.
- Assigns game title and gameid to destination folder
- Reads disc number, renaming iso 2 file to disc2, instead of game.iso
I assume a iso didn't match the list, but it closes to soon to see. Instead of continuing to the next iso it just stops. Also It has occasionally only half completed a couple.
Any help would be appreciated.
import os
import re
import shutil
total_games = 0
dir = "./"
dirs = os.listdir("./")
wiitdb = open("wiitdb.txt", "r")
for root, dirs, files in os.walk(dir):
if 'games' in dirs:
dirs.remove('games')
for file in files:
if file.endswith(".iso"):
pathfile = os.path.join(root, file)
print("Reading file: "+ pathfile)
f = open(pathfile)
f.seek(0)
header = f.read(7)
gameid = header[:6]
disc_number = ord(header[-1:])
disc_number += 1
print("GameID: "+ gameid + " Disc: "+ str(disc_number))
match = re.search(r'\w+', gameid)
if match:
if not os.path.exists(dir + "games"):
os.makedirs(dir+"games")
with open("wiitdb.txt", encoding='utf-8') as wiitdb:
for line in wiitdb:
m= re.match(gameid+r" = ([\w\W\s]+)", line)
if m:
gamename = m.group(1)
if ":" in gamename:
gamename = gamename.replace(':', ' - ')
if "\n" in gamename:
gamename = gamename.replace ('\n', '')
print("Game title: "+gamename)
newgamepath = dir+"games"+"/"+gamename+" ["+gameid+"]"
if not os.path.exists(newgamepath):
os.makedirs(newgamepath)
print("Copying game...")
shutil.copy(pathfile, newgamepath + "/game.iso")
total_games += 1
if not os.path.exists(newgamepath+"/disc"+ str(disc_number)+".iso") and disc_number > 1:
print("Copying game...")
shutil.copy(pathfile, newgamepath + "/disc"+ str(disc_number) +".iso")
total_games += 1
else:
print("GameID: Invalid!!")
print("====================================")
print("Total games copied: " + str(total_games))
