Requirements Description:
1, the current directory has a lot of folders, files, statistics/usr/local/This directory, if it is a folder, to delete
/usr/local/
F1 W1 F2 W2 W3 W4 F4
W1 W2 W10.txt
Requirements Analysis:
1, first list all the files in the directory, with Os.listdir ()
2, determine if it is a file, Os.path.isfile ()
ImportOsf_dir=OS.GETCWD ()#Get current directoryL_dir=os.path.join (F_dir,'usr\local')#stitching into full usr/local pathLis_dir=os.listdir (L_dir)#list all the files in the directory, generate a list#print (Lis_dir) forPinchlis_dir:d1=Os.path.join (l_dir,p)#print (D1) ifOs.path.isfile (D1) = =FALSE:FD=Os.path.abspath (D1)#print (FD)fd_list=Os.listdir (FD)#print (fd_list) forWinchFd_list:fw_dir=Os.path.join (fd,w)#print (Fw_dir)Os.remove (fw_dir) os.rmdir (FD)
Python exercises-List all files in the directory Delete folder