Search code examples
pythonpanda3d

Cannot mkdir, file not found


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


Solution

  • 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.")