Question

How can I make the program verify if it's already on the targeted locations, and if not, move itself to another location?

Was it helpful?

Solution

os.path.abspath(__file__) is the absolute path to the current module's (or main script's) present location, and os.rename is a way to move a file (not to a location where another file of the same name is already present, though; you'd have to os.unlink the latter first).

OTHER TIPS

An alternative to os.path.abspath(__file__) that works with py2exe is sys.executable. if you say filename = sys.executable.rsplit('\\',1)[1] filename would be your files name. this only works if you compile your programs with py2exe though since otherwise it will just display pythonw.exe or python.exe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top