The code is as follows:
#!/usr/bin/env python
##-*-Coding:utf-8-*-
Import OS
Print "N Welcome everyone to learn Python with me";
System=os.name; #获取系统的类型
if (system== "NT"):
Print "The operating system you are using is Windows";
Print "The specific path separator represented by Windows is" +OS.SEP; #获取系统的分隔符
Print "The Terminator effect of your computer system" +OS.LINESEP; #获取系统换行符
Else
Print "The operating system you are using is Linux";
Print "The specific path separator represented by Windows is" +OS.SEP;
Print "The Terminator of your computer system is" +OS.LINESEP;
PATH=OS.GETCWD (); #获得当前目录
Print "The directory where you are running this program is" +PATH;
Print "Your computer's PATH environment variable is" +os.getenv ("path"); #获取环境变量的值os. Putenv (Key,value) to set the value of an environment variable
Print "The files in your current folder are:";
Print Os.listdir (path); #获取文件夹中的所有文件
if (os.path.exists ("Test.txt")): #判断文件是否存在
Os.remove ("Test.txt") #删除指定文件
Print "n Delete succeeded";
Else
Print "N file does not exist";
Print "Let's delete a file, delete the result after:";
Print Os.listdir (path);
Print "N View your Ip:n";
Print Os.system ("ipconfig"); #执行系统命令
Filepath1= "C:python27";
Filepath2= "c:python27os.py";
if (Os.path.isfile (filepath2)): #判断是不是文件
Print filepath2+ "is a file";
if (Os.path.isfile (filepath1)):
Print filepath1+ "is a file";
Else
Print filepath1+ "not a file";
Name= "os.py";
Print "The size of this program is";
Print os.path.getsize (name); #获取文件大小
Name=os.path.abspath (name); #获取文件的绝对路径
Print "The absolute path of this program is" +NAME;
Print "The file name of the path of this program is:";
Print os.path.split (name); #将文件名和路径分开
Files=os.path.splitext (name); #将文件名和扩展分开
Print "The extension of this program is" +files[1];
Print "The file name of this program is" +os.path.basename (name); #获取文件的名字
Print "The path to this program is" +os.path.dirname (name); #获取文件的路径