Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Python file directory in Python
#1
Hi!

I am trying to get the directory in which my Python program is saved. However, using the following code, I always get back the AppData/Local/Temp folder. Is it possible in RoboDK to get my original directory? For my specific purpose, it is also okay to get the directory of where my RoboDK file is stored.

Example:

import os
DIR = os.path.dirname(os.path.realpath(__file__))
print(DIR)

Result:
C:\Users\MyName\AppData\Local\Temp

Thank you for your help!
#2
(10-05-2021, 07:59 PM)JobdV Wrote: Hi!

I am trying to get the directory in which my Python program is saved. However, using the following code, I always get back the AppData/Local/Temp folder. Is it possible in RoboDK to get my original directory? For my specific purpose, it is also okay to get the directory of where my RoboDK file is stored.

Example:

import os
DIR = os.path.dirname(os.path.realpath(__file__))
print(DIR)

Result:
C:\Users\MyName\AppData\Local\Temp

Thank you for your help!

Running a script that is held in RoboDK's tree will always return a path in %TEMP%, as RoboDK keeps an internal copy of the script.

If you wish to run a python script that is not saved in RoboDK, I suggest you take a look at RoboDK Apps!
More info here: https://github.com/RoboDK/Plug-In-Interf...nAppLoader
  




Users browsing this thread:
1 Guest(s)