1. Original file
Required Files:
#-*-Coding:utf8-*-ImportOSdefsplitsentence (inputfile,name): Fin= Open (Inputfile,'R')#open a file in a read way Printname Fout= Open ('/home/xdj/abstract1/'+name,'W')#open a file in the way it was written forEachlineinchFin:if 'abstract=' incheachLine:fout.write (eachline)#writes the result of the word breaker to the output file.fin.close () fout.close () path='/home/xdj/abstract'FNS=[os.path.join (ROOT,FN) forRoot,dirs,filesinchOs.walk (PATH) forFninchFiles]i=-1; forFinchfns:i=i+1splitsentence (f,files[i])
root for '/home/xdj/abstract'
Dirs is empty
Files as 'abstract' in
# -*-Coding:utf8-*- Import operator from Import Listdir Import os fileList=os.listdir ('/home/xdj/abstract') filelist.sort () Print fileList
[' 2007.BibTeX ', ' 2008.BibTeX ', ' 2009.BibTeX ', ' 2010.BibTeX ', ' 2011.BibTeX ', ' 2012.BibTeX ', ' 2013.BibTeX ', ' 2014. BibTeX ', ' 2015.BibTeX ']
Before sort ()
[' 2012.BibTeX ', ' 2013.BibTeX ', ' 2008.BibTeX ', ' 2009.BibTeX ', ' 2014.BibTeX ', ' 2010.BibTeX ', ' 2007.BibTeX ', ' 2011. BibTeX ', ' 2015.BibTeX ']
############### #33
Sort () is matched from left to right, not simple comparison size
Python handles files in a folder (create a new file to save), Listdir sequential output