Program9 Done 16apr18

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

import os

x = os.getcwd()
print "x is the current working dir of mine..= ",x

print "*******" * 5

#fn defn1 for get current working directory


def os_fun1():
x = os.getcwd()
print "x = ",x

def os_fun2():
x1 = os.listdir(".")
print "x1 = ", x1

def os_fun3():
x3 = os.listdir("My_test_dir")
print "x3 = ", x3

#mofidy this functiio3 by passing the directory as a parmeter


def os_fun3a(dirname):
my_dirname = os.listdir(dirname)
#print "my_dir_name =", my_dirname
return my_dirname

#commands
x=os.listdir("My_test_dir")
x4 = type(x)
print "the values given in the directory =", x
print "type of x4 is ",x4

x5 = len(x)
print "x5 = ", x5

#slicing of list:
x6 = x[:1]
print "no of files x6 =", x6

x6 = x[:]
print "no of files x6 =", x6
print "\n"

#same output as above x6


x6a = x[:5]
print "no of files x6a =", x6a
print "\n"

x7 = x[-1:]
print "x7 last one is ", x7

x7 = x[-2:]
print "x7 last one is ", x7

x8 = x[-5:]
print 'x8 is :', x8
print "****$$$****" * 5
#call fn1
os_fun1()

#call fn2
os_fun2()

#call fn3
os_fun3()

print "\n"
print "****$$$****" * 5

#call fn3a
my_result3 = os_fun3a("My_test_dir")
print "my_result3 =",my_result3

#end of the script


print "thanks.."

****************
Assignment:

1.import os:
implement the concept of multidepth folders (ie create folder1, and create another
folder named folder2 inside the folder1, create some files in folder 1 and
folder2 , then find the current working directory , get the list of files in
folders.

2. pass inside folder as a parameter to the function and then list the files..

You might also like