File Operations Using Python3

1. How To Get Meta Data Of A File using Python 3.

ff=open("c:\\demo\\a.txt","r")
print(ff.name)
print(ff.closed)
print(ff.mode)
ff.close()
print(ff.closed)

2. How To Read Content Of A File using Python3.

ff=open("b.txt","r")
str=ff.read(10)#This Line is meant for reading maximum 10 characters from a file
print(len(str))#Print the size of the content in file
print(str)

3. How To Write Content Into A File using Python3.

ff=open("dinesh.txt","a")
ff.write("Jiban")
ff.close()

4. How To Get Cursor Position From A File using Python3.

ff=open("b.txt","r")
print(ff.tell())
str=ff.read()
print(ff.tell())
ff.close()

5. How To Set Cursor Position In A File At Specific Position using Python3.

ff=open("b.txt","r")
ff.seek(2,0) #It Will Set Cursor At 0th row 2nd Column 
str=ff.read()
#print(ff.tell())
print(str)
ff.close()

6. File And Folder Related Operations using Python3.

import os
os.remove("a.txt")#This is Meant For Removing The File 
os.removedirs("C:\\xampp")#This is Meant For Removing The Directory
os.rmdir("End2")#This is Meant For Removing The Directory
os.mkdir("End2")#This is Meant For Creating The Directory
os.link("b.txt","c:\\demo\\c.txt") #This is Meant For Creating A Duplicate File for b.txt   
# as c.txt in C drive and demo folder , make sure you have demo folder in C drive.
os.unlink("c.txt")#This Is Meant For Deleting The File specified.