In [1]:
fp=open('D:\\fd.txt','w') #absolute path name ,new file fd.txt will create in D drive
fp.close()
In [5]:
fp=open('D:\\filc.txt','w') #absolute path name ,new file filc.txt will create in D drive
fp.close()
In [7]:
f=open('.\\filw.txt','w') #relative path name ,new file filw.txt will create in current working Directory
In [9]:
import os
print(os.getcwd())
In [12]:
f=open('D:\\rks\\filrks.txt','w') #new File filrks.txt will create in rks folder in D drive
f.close()
In [13]:
f=open('.\\desktop\\fildesk.txt','w') # new file fildesk.txt created in desktop folder of current directory
f.close()
In [3]:
f=open('.\\desktop\\fildesk.xls','w')# new file fildesk.txt created in desktop folder of current directory
f.writelines([1,2,3])
f.close()
In [4]:
import os
print(os.getcwd())
In [8]:
os.chdir("D:")
print("Directory changed")
In [9]:
os.chdir("C:")
print("Directory changed")
In [10]:
print(os.getcwd())
In [11]:
os.mkdir('binf')
In [15]:
os.mkdir('C:\\binf1')
In [17]:
os.mkdir('D:\\binf2')
In [19]:
print(os.getcwd())
In [20]:
os.mkdir('D:\\binf2\\binf22')
In [21]:
print(os.getcwd())
In [22]:
os.chdir("C:\\binf")
In [23]:
print(os.getcwd())
In [30]:
f=open('filecs.txt','w')
f.close()
In [32]:
print(os.getcwd())
In [36]:
isExist = os.path.exists('C:')
print(isExist)
In [38]:
isExist = os.path.exists('C:\\binf')
print(isExist)
In [40]:
try :
if(os.path.exists('C:\\fold')==False:
os.mkdir('c:\\fold')
except:
print('path exist already')
In [ ]: