<p>In relation to <a href="https://stackoverflow.com/questions/283431/why-would-an-command-not-recognized-error-occur-only-when-a-window-is-populated">another question</a>, how do you account for paths that may change? For example, if a program is calling a file in the same directory as the program, you can simply use the path ".\foo.py" in *nix. However, apparently Windows likes to have the path hard-coded, e.g. "C:\Python_project\foo.py".</p>

<p>What happens if the path changes? For example, the file may not be on the C: drive but on a thumb drive or external drive that can change the drive letter. The file may still be in the same directory as the program but it won't match the drive letter in the code.</p>

<p>I want the program to be cross-platform, but I expect I may have to use <strong>os.name</strong> or something to determine which path code block to use.</p>

If your file is always in the same directory as your program then:
```
```
def _isInProductionMode():
    """ returns True when running the exe, 
        False when running from a script, ie development mode.
    """
    return (hasattr(sys, "frozen") or # new py2exe
           hasattr(sys, "importers") # old py2exe
           or imp.is_frozen("__main__")) #tools/freeze

def _getAppDir():
    """ returns the directory name of the script or the directory 
        name of the exe
    """
    if _isInProductionMode():
        return os.path.dirname(sys.executable)
    return os.path.dirname(__file__)
```
```
should work. Also, I've used py2exe for my own application, and haven't tested it with other exe conversion apps.