1,105,320 Community Members

Recognizing Extensions

Member Avatar
clouds_n_things
Junior Poster in Training
51 posts since Jan 2013
Reputation Points: 13 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

So my program is progressing quite nicely, and I'm semi-proud of myself for getting this far (I'm a newbie), but I had 2 questions. One question is that my program recognizes a .CFG extension...but never finds games with any other extension (.smc, .srm). I type it in EXACTLY as it is in the folder its in, and im sure that the function isnt written wrong because it returns True for the only game I had as a CFG format. Any ideas?

Also, how would one import photos and files and things to use in a python program (such as pictures for backgrounds, jpegs to be used inside the program, etc)?

Thanks! :)

import os, time, subprocess, shlex, logging, platform
from tkinter import * 


try:
    import Tkinter as tk
    from urllib2 import urlopen

except ImportError:
    import tkinter as tk
    from urllib.request import urlopen

def debug():
    if platform.platform().startswith('Windows'):
        logging_file = os.path.join(os.getenv('HOMEDRIVE'), os.getenv('HOMEPATH'), 'konsole_kollection.log')
    else:
        logging_file = os.path.join(os.getenv('HOME'), 'konsole_kollection.log')
    print('Logging To: ', logging_file)
    logging.basicConfig(
        level=logging.DEBUG,
        format ='%(asctime)s :  %(levelname)s : %(message)s',
        filename = logging_file,
        filemode = 'w',
    ) 

    logging.debug("Start")
    logging.info("Running")
    logging.warning("Warnings")
    logging.critical("P0 Errors")
    logging.error("P1 Errors") 

def videoGame():
    '''This function opens up the Snes9x player in the Applications folder.'''
    print(videoGame.__doc__)
    # export PYTHONPATH=/Users/xxxx/Desktop/Python3:$PYTHONPATH
    logging.debug('Initializing SNES Locator')
    extensions =('.src', '.srm', '.CFG') 
    subprocess.call(['ls', '/SNES/SNESRoms'])
    while True: 
        command_line = input('Enter the game you would like to search for: ')
        for data in os.listdir('/SNES/SNESRoms'):
            if command_line.endswith(extensions):
                arguments = shlex.split(command_line)
                print(arguments)
                master_process = subprocess.Popen(["open /Applications/Snes9x.app", command_line], shell=True, 
                executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False,
                cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0)
                logging.info('Running SNES Locator')
                return False
            else:
                print('Invalid input error, please enter a valid game format.')
                logging.error('Error Code 1: Invalid Input Error')
                break
    else:
        print(command_line) 
Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
0
 

Your extensions may be case sensitive.

Member Avatar
clouds_n_things
Junior Poster in Training
51 posts since Jan 2013
Reputation Points: 13 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

All the extensions in the snes folder are all lowercase, which is why they are lowercase in the code. Its just not recognizing anything but .CFG for some reason.

Member Avatar
woooee
Posting Maven
2,796 posts since Dec 2006
Reputation Points: 783 [?]
Q&As Helped to Solve: 836 [?]
Skill Endorsements: 12 [?]
 
0
 

Do you want to search for a file name ending, "data" i.e. list of files, if not, state what you do want the program to do?? Now you do the same search [the result from input()] for each file name returned from os.listdir

    command_line = input('Enter the game you would like to search for: ')
    for data in os.listdir('/SNES/SNESRoms'):
        if command_line.endswith(extensions):
Member Avatar
clouds_n_things
Junior Poster in Training
51 posts since Jan 2013
Reputation Points: 13 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

If the data endered ends with one of the 3 extensions, I would like it to be returned and the snes emulator to be opened. It works with one game with a .CFG function, but for the rest of the smc or srm files, it wont recognize and and kicks back the error code that I wrote (line 51). Basically, the basic gist of the program is to list the games, have the user input any game, and that game to be opened with Snes9x. :)

Member Avatar
snippsat
Veteran Poster
1,040 posts since Aug 2008
Reputation Points: 483 [?]
Q&As Helped to Solve: 381 [?]
Skill Endorsements: 10 [?]
 
1
 

If the data endered ends with one of the 3 extensions, I would like it to be returned and the snes emulator to be opened.

Your logic dos not make sense to me.
If user input game.smc,should all files that has a smc extensions be found?
Explain your self better.

You never use data returned by os.listdir('/SNES/SNESRoms').
data return are all files in /SNES/SNESRoms,but if you never use it what's the point?

What i mean is this,here i use data to do something.

for data in os.listdir('/SNES/SNESRoms'):
    print data #all files in /SNES/SNESRoms that you never use
    if data.endswith(extensions):
        print data #all files that ends with extension definde before in extensions.
Member Avatar
clouds_n_things
Junior Poster in Training
51 posts since Jan 2013
Reputation Points: 13 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

The subprocess.call lists every single rom inside of the SNES Roms folder, at that point the user is given the option to enter a full title of a game, and if that game is found, it should be open with SNES9x. For instance, if a game with the title of ZSNESW.CFG is found in the subprocess.call list, it should be popped open with the SNES9x player.

The only game that this works properly with IS the ZSNESW.GAME. Every other game that the user enters with a .smc or .srm extension is NEVER recognized by the player, and instead kicks back the error code and prompts the user to enter the game again. What it basically boils down to is, the only game that works is ZSNESW.CFG, but every single .smc or .srm file that is put in (and matches one of the names in the subprocess call) should be opened with SNES emulator.

Member Avatar
clouds_n_things
Junior Poster in Training
51 posts since Jan 2013
Reputation Points: 13 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

So a small update, in case I forgot to mention, CFG is the configuration file for SNES, so it finds the config file...but not the rom files.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article