Friday, September 30, 2011

Python shutil

#!/usr/bin/python
#Author: Balasubramaniam Natarajan
#Demonstrate how to use file I/O high-level module
import shutil

#we will create an alias for shutil like s
s = shutil
#This would change the date and time on the file which is created
s.copy("data1","data2")
#This would not change the date and time on the file which is created
s.copy2("data1","data3")
#This would move data1 to the destination path
s.move("data2","/home/bala/data3")
#If we want to move an entire directory
src="bala"
dst="bullet"
s.copytree(src,dst)

dst="bullet1"
#The third argument if it is 0 we will copy the symbolic link file directly, if it is 1 it will just copy the symbolic link
s.copytree(src,dst,0)

dst="bullet"
s.rmtree(dst)

#END

No comments:

Post a Comment