Playing in Windows with python

Hi Friends today I have used the python os module to play around the windows os.
Here I list some of the python commands I have used in my Windows OS.
To Print the OS name been used :

>>> import os
>>> print os.name
nt

To get the language used in the OS :

>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'cp1252')

To open a folder in any directory we can use startfile command which works only for windows:

>>> import os
>>> os.startfile('F:/')

To delete a file using python on Windows:

>>> import glob
>>> import os
>>> for text in glob.glob("E:\\*.txt"):
os.remove(text)

---> here text is a text file in the E:\\ directory.

No comments:

Post a Comment