Home > Backend Development > Python Tutorial > python modify files

python modify files

巴扎黑
Release: 2016-12-09 14:28:28
Original
1480 people have browsed it

   #!/usr/bin/env python 
   #coding=utf-8 
   
   import os 
   import sys 
   
   pubid0=0000000 
   pubid1=1111111 
   path=1111111 
 
 def get_filenames(fdir): 
 
     return os.listdir(fdir) 
 
 def rename_file(filename,pubid0,pubid1): 
 
     os.rename(filename,filename.replace(pubid0,pubid1)) 
 
 
 if __name__ == '__main__': 
 
    path = sys.argv[1] 
    pubid0 = sys.argv[2] 
    pubid1 = sys.argv[3] 
    print '\t path :',path,'\t pubid0:',pubid0,'\t pubid1:',pubid1 
    print '\t\t***************************************\n' 
 
    filesname = get_filenames(path) 
    for i in filesname: 
 #       print i ,os.path.join(path,i) 
        nPos =str(i).find(pubid0) 
        if nPos > 0: 
           rename_file(os.path.join(path,i),pubid0,pubid1) 
           print os.path.join(path,i)
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template