OS Module in Python:-
It is used to perform the operation in a file under an operating system such as create a directory, change directory, remove directory, rename the file, delete the file, etc.
complete program explanation:-
import os
#os.mkdir("hello")
os.chdir("hello")
#os.mkdir("hello1")
f=open("hello1.txt","w")
f.write("hello world")
f.close()
os.remove("hello1.txt")
#os.rmdir("hello1")
print(os.getcwd())
#print(os.listdir("c:"))
print(os.listdir())
location = 'd:/c/'
for file in os.listdir(location):
# if file.endswith(".c"):
print(os.path.join(location, file))
Assignment of os module:-
1) WAP to count total folder in the computer, drive, max size folder, total image for the particular director, total video on the directory, total python program in the computer.
Q:- WAP to count total folder in the drive ?
ReplyDeleteSolution: -
import os
print("The Total Number of Folder's are available in Given Path are : -")
print(len(os.listdir('C:/')))
Post a Comment
If you have any doubt in programming or join online classes then you can contact us by comment .