Tag:python practice
#!/usr/bin/env pythonimport osimport sysdef get_curlist (PATH): cur_files = os.listdir (PATH) All_files = [] for file_name in cur_ Files: full_ Name = os.path.join (Path,file_name) all_files.append (full_name) if os.path.isdir (Full_Name): next_levelfiles = get_curlist (full_name) all_files.extend (next_Levelfiles) return all_Filesitem_Path = '/usr/local/webapp/ Document ' File_path = get_curlist (item_path) item_newpath = '/usr/local/webapp/document_ NewDocument ' Newfile_path = get_curlist (item_newpath) def add_file (): add_List=[] for num in Range (0,len (newfile_path)): renewfile_path=newfile_path[num].replace (' _newdocument ', ') if renewfile_path not in file_Path: add_list.append (Renewfile_path) return add_listadd_ Filelist = add_file () file_add = open ('/tmp/python_addfile ', ' W ') file_add.truncate () for num in range (0,len (add_filelist)): file_add = open ('/tmp/python_addfile ', ' a ') file_add.write (Add _filelist[num]+ ' \ n ') file_add.close () Def del_file (): del_ File=[] for num in range (0,len (File_Path)): refile_path= File_path[num].replace (item_path,item_path+ ' _newdocument ') if refile_Path not in newfile_Path: &nbSp; del_ File.append (Refile_path) return del_Filedel_Filelist = del_file () file_add = open ('/tmp/python_delfile ', ' W ') file_add.truncate () for num in range (0,len (del_filelist)): file_add = open ('/ Tmp/python_delfile ', ' a ') file_add.write (del_Filelist[num]+ ' \ n ') File_add.close ()
The script is mainly to compare documents and document_newdocument, through replace to modify the obtained file path, compare the file path of another directory to determine whether the file exists on both sides.
The addfile refers to documents that are not in document but in Document_newdocument.
Delfile refers to documents inside the document but not in Document_newdocument.
This article is from the "Empty Heart" blog, please be sure to keep this source http://songknight.blog.51cto.com/2599480/1632808
[Python practice] compares the file differences in two directories and gives a list of differences