In the interpreter for my programming languages I have to correctly handle the parts in case the import function is called. I then need to check if such a file is in the /libs folder (located at the same place as my executeable!) and if it doesn’t exist I have to check in the directory of the current script.
- How can I get the exact path to the directory where the executeable is located from argv?
-
What is the best way to remove the file from the end of a path, e.g:
C:/a/b/c/file.exeshould becomeC:/a/b/c/
argv[0]but whether that has the full path or just the name of the binary depends on the platform and how your process was invoked.strrchrto find the last slash and replace the character after it with'\0'Code example: