Home > Enterprise >  How to know where is windows installed with Python?
How to know where is windows installed with Python?

Time:09-21

I am writing a program that needs to know which Drive is Windows drive . because I need to go to "Windows-Drive:\Users\publick\Desktop", I need some code or module that will give me the windows drive. Thanks for your kindness.

CodePudding user response:

I found my Answer!

`import os

Windows-Drive=os.path.dirname(os.path.dirname(os.path.join(os.path.join(os.environ['USERPROFILE']))))

This code is answer!

CodePudding user response:

#!/usr/bin/env python3


# Python program to explain os.system() method 
      
# importing os module 
import os 
  
# Command to execute
# Using Windows OS command
cmd = 'echo %WINDIR%'
  
# Using os.system() method
os.system(cmd)        # check if returns the directory [var = os.system(cmd) print(var) ] in Linux it doesnt

# Using os.popen() method
return_value = os.popen(cmd).read()

can you check this approach ? I am not on Win

  • Related