-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile3.py
More file actions
39 lines (27 loc) · 734 Bytes
/
file3.py
File metadata and controls
39 lines (27 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Create a new file
fo = open ("foo.txt","w+")
fo.write ("Hey welcome to the file tutorials\nstart reading and writing file in python\n")
print ("file name : ",fo.name)
fo.close()
# Read file
fo = open("foo.txt","r+")
str = fo.read(20)
print (str)
#Rename file
import os
os.rename("foo.txt","bar.txt")
print ("file name after rename : ",fo.name)
# Delete file
os.remove("bar.txt")
print ("Done with files operations")
print ("\n Directory operations")
# Create direcotry
os.mkdir("test_dir")
#Change the dir
os.chdir("/home/spathare/python-practise/test_dir")
# get current dir
print("current dir path : ",os.getcwd())
# Chage directory
os.chdir("/home/spathare/python-practise")
# Remove the dir
os.rmdir("test_dir")