1+ import uos
2+
3+ def main ():
4+ # 创建文件 此处并没有对文件进行写入操作
5+ f = open ("/usr/uos_test" ,"w" )
6+ f .close ()
7+ del f
8+
9+ # 查看文件是否存在
10+ t = uos .listdir ("/usr" )
11+ print ("usr files:{}" .format (t ))
12+
13+ if "uos_test" not in t :
14+ print ("file not exist test fail" )
15+ return
16+
17+ # 查看文件状态
18+ a = uos .stat ("/usr/uos_test" )
19+ print ("file size:{}bytes" .format (a [6 ]))
20+
21+ # 重命名文件
22+ uos .rename ("/usr/uos_test" , "/usr/uos_test_new" )
23+ t = uos .listdir ("/usr" )
24+ print ("test file renamed, usr files:{}" .format (t ))
25+
26+ if "uos_test_new" not in t :
27+ print ("renamed file not exist test fail" )
28+ return
29+
30+ # 删除文件
31+ uos .remove ("/usr/uos_test_new" )
32+ t = uos .listdir ("/usr" )
33+ print ("remove test file, usr files:{}" .format (t ))
34+
35+ if "uos_test_new" in t :
36+ print ("remove file fail, test fail" )
37+ return
38+
39+ # 目录操作
40+ t = uos .getcwd ()
41+ print ("current path:{}" .format (t ))
42+ uos .chdir ("/usr" )
43+ t = uos .getcwd ()
44+ print ("current path:{}" .format (t ))
45+ if "/usr" != t :
46+ print ("dir change fail" )
47+ return
48+
49+ uos .mkdir ("testdir" )
50+ t = uos .listdir ("/usr" )
51+ print ("make dir, usr files:{}" .format (t ))
52+
53+ if "testdir" not in t :
54+ print ("make dir fail" )
55+ return
56+
57+ uos .rmdir ("testdir" )
58+ t = uos .listdir ("/usr" )
59+ print ("remove test dir, usr files:{}" .format (t ))
60+
61+ if "testdir" in t :
62+ print ("remove dir fail" )
63+ return
64+
65+ if __name__ == "__main__" :
66+ main ()
0 commit comments