Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Open computer drives like C, D or E using Python

  • Last Updated : 29 Dec, 2020

Have you ever wondered that you can open your drives by just typing C, D or E and then that drives are open.This can be possible by using Python. So, for performing this task this we are using os.startfile() method of OS library. This Method start a file with its associated program.

Syntax: os.startfile(file_name)

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Return: None.



Now let’s see the code:

Python3




# import library
import os
  
# take Input from the user 
query = input("Which drive you have to open ? C , D or E: \n")
  
# Check the condition for 
# opening the C drive
if "C" in query or "c" in query:
  os.startfile("C:")
    
# Check the condition for 
# opening the D drive
elif "D" in query or "d" in query:
  os.startfile("D:")
  
# Check the condition for 
# opening the D drive
elif "E" in query or "e" in query:
  os.startfile("E:")
  
else:
    print("Wrong Input")

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :