Python Forum
script closed before i can see the error that occurs?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
script closed before i can see the error that occurs?
#1
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.
  • 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
Now the issues. If it comes across an error it automatically closes before I can see what issue or iso caused the error. It ran fine through a few iso's. Than it hit a hiccup.
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))
Reply


Messages In This Thread
script closed before i can see the error that occurs? - by wrestlemy69 - Dec-01-2016, 05:19 PM
RE: Script help - by micseydel - Dec-01-2016, 05:30 PM
RE: Script help - by wrestlemy69 - Dec-01-2016, 05:38 PM
RE: Script help - by nilamo - Dec-01-2016, 06:03 PM
RE: Script help - by snippsat - Dec-01-2016, 06:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [closed] check whether an integer is 32 or 64 bits paul18fr 4 281 May-27-2024, 04:55 PM
Last Post: deanhystad
  This result object does not return rows. It has been closed automatically dawid294 6 1,669 Mar-30-2024, 03:08 AM
Last Post: NolaCuriel
  OSError occurs in Linux. anna17 2 483 Mar-23-2024, 10:00 PM
Last Post: snippsat
  A question about 'Event loop is closed' fc5igm 2 2,402 Oct-05-2021, 02:00 AM
Last Post: fc5igm
  ValueError: I/O operation on closed file problem aliwien 0 2,193 Apr-23-2021, 05:50 PM
Last Post: aliwien
  Run an app in a standalone terminal and wait until it's closed glestwid 2 2,627 Aug-30-2020, 08:14 AM
Last Post: glestwid
  how do i loop a "def ..." when error occurs? Stan2292 0 1,684 Aug-12-2019, 05:28 AM
Last Post: Stan2292
  Inclusive (closed) range with float numbers mapg 4 4,164 Apr-27-2019, 09:09 PM
Last Post: Gribouillis
  New df from existing when condition occurs Devilish 0 1,427 Jan-10-2019, 12:03 AM
Last Post: Devilish
  VMware View - Session opened/closed? hhh 0 2,396 May-31-2018, 10:10 AM
Last Post: hhh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020