compare two windows paths, one containing tilde, in python

Posted by Steve Cooper on Stack Overflow See other posts from Stack Overflow or by Steve Cooper
Published on 2010-04-29T15:12:57Z Indexed on 2010/05/29 14:32 UTC
Read the original article Hit count: 486

I'm trying to use the TMP environment variable in a program. When I ask for

tmp = os.path.expandvars("$TMP")

I get

C:\Users\STEVE~1.COO\AppData\Local\Temp

Which contains the old-school, tilde form. A function I have no control over returns paths like

C:\Users\steve.cooper\AppData\Local\Temp\file.txt

My problem is this; I'd like to check if the file is in my temp drive, but I can't find a way to compare them. How do you tell if these two Windows directories;

C:\Users\STEVE~1.COO\AppData\Local\Temp
C:\Users\steve.cooper\AppData\Local\Temp

are the same?

© Stack Overflow or respective owner

Related posts about python

Related posts about Windows