I'm working on a script to change a value in a txt file and then start up an application afterwards. I just cannot figure out how to get an absolute path. So calling os.system(path) is constantly failing because of a space in the directory I'm opening.
I've tried:
- PureWindowsPath('path')
- p = Path(path).resolve()
- path = os.path.abspath(os.path.dirname(path))
Here is the part of the code:
def runtime(self):
""" The container to execute the Class functions. """
print('This script changes the X axis resolution value for Rocket League.\nThe game will launch after a value is entered.\n')
path = os.path.abspath(os.path.dirname(open('config.txt').readlines()[1][11:] + 'common\\rocketleague\\Binaries\\Win32\\'))
print(path)
inp = input('Enter 1 for 1 Monitor.\nEnter 2 for 2 Monitors.\nEnter C to cancel\n').lower()
if inp == '1':
self.replace(self.ConfigFilePath, self.Monitors2, self.Monitors1)
elif inp == 'c':
return None
else:
self.replace(self.ConfigFilePath, self.Monitors1, self.Monitors2)
print('Starting Rocket League...')
os.system('START /D ' + str(path) + ' "" /wait RocketLeague.exe')
time.sleep(2)
Output of execute.runtime() :
This script changes the X axis resolution value for Rocket League.
The game will launch after a value is entered.
D:\STEAM GAMES\steamapps\common\rocketleague\Binaries\Win32
Enter 1 for 1 Monitor.
Enter 2 for 2 Monitors.
Enter C to cancel
1
Starting Rocket League...
The system cannot find the file GAMES\steamapps\common\rocketleague\Binaries\Win32.
Thanks for taking a look!