2

I'm making a game, and I made a log system. It makes a new directory and makes a .log file in it. I released it today only to find that it doesn't work. It works fine for me, yet not to others. I have tried makedirs but to no avail. Here is the code:

if not os.path.exists('C:/ToontownRebuilt/src/user/logs/'):
    os.mkdir('C:/ToontownRebuilt/src/user/logs/client')
    self.notify.info('Made new directory to save logs.')

and here is the traceback the people (one reported it to me) suffering the error got:

:ClientStart: Reading user/preferences.json...
Traceback (most recent call last):
File "C:\ToontownRebuilt\src\dependencies\panda\python\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\ToontownRebuilt\src\dependencies\panda\python\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\ToontownRebuilt\src\toontown\toonbase\ClientStart.py", line 94, in <module>
__builtin__.launcher = TTSLauncher()
File "toontown\launcher\TTSLauncher.py", line 34, in __init__
WindowsError: [Error 3] The system cannot find the path specified: 'C:/ToontownRebuilt/src/user/logs/client'

Any help is appreciated with this issue. It has gotten me beat. It works for me, but not others. Why? How can I fix it? Also, if this question wasn't good, can you comment some tips on how to make it better? Thank you! :D

4

2 回答 2

0

The other users may not have directories called

    ToontownRebuilt
    user

Or

    src

Shorten to:

    os.mkdir('user/logs/client')
于 2016-02-27T08:43:04.243 回答
-1

You could make use of a try..except statement, if the path must be fixed.

if not os.path.exists('C:/ToontownRebuilt/src/user/logs/'):
    try:
         os.mkdir('C:/ToontownRebuilt/src/user/logs/client')
         print('Made new directory to save logs.')
    except:
         print("Unable to create C:/ToontownRebuilt/src/logs/client\nPlease create manually and try again.")
于 2016-02-27T09:30:38.650 回答