0

If I use tempfile.gettempdir() I receive the path to the Temp directory but the path is written with only small letters:

c:\\users\\test\\appdata\\local\\temp

My problem is that I have a program that work with lists and add exception rules which are case sensitive. I need the path to be written as it's written in the CMD on the computer and if I use os.path.dirname(os.path.abspath())

C:\\Users\\Test\\AppData\\Local\\Temp

Any ideas how this can be achieved?

Lavonen
  • 606
  • 1
  • 10
  • 21
  • 1
    Possible duplicate of [How can I get the proper capitalization for a path?](https://stackoverflow.com/questions/27465610/how-can-i-get-the-proper-capitalization-for-a-path) – Dekel Jan 02 '18 at 00:13

1 Answers1

2

You could use os.environ to access environment variables, so in this case

os.environ['TEMP']
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
  • Is `TEMP` actually reliable for this? As in: does it make a difference if the case is not correct in there? (I ... don't actually know how to check. Change it, then test all software on my system?) – Jongware Jan 02 '18 at 00:12
  • Yes you can rely on `TEMP` being defined, and no the case of the environment variables is not important in this case. The environment variables will be those you could access from e.g. the command prompt such as `%APPDATA%`, `%TEMP%`, `%PATH%`, etc. The `environ` dict is just a collection of those paths. – Cory Kramer Jan 02 '18 at 00:15
  • Sorry, I mean that the *case* of a path inside `TEMP` could also be different from the actual pathname. Sure, usually (at least for common users) it is changed by the system. But then again, for most uses the case does not matter either. – Jongware Jan 02 '18 at 00:18