Volume delete C and C + + comments

Source: Internet
Author: User

Using the Python language to implement bulk deletion of a/C + + type annotation
1. The current support for removing. H. hpp. C. cpp. Java these source files are annotated with//or/**/

2. Recursive traversal directory support

3. The current version is Python2.7 version, it is only installed Python2.7 (or python3.x The following version of the only can be used directly, test no problem will be compiled EXE direct use)

4. How to use:
(1) Create a source directory, such as D:\SRC (preferably not in the path of Chinese);
(2) Establish the target directory, such as D:\DST (preferably not in Chinese in the path);
(3) Place the removecomment.py somewhere (preferably not Chinese in the path), such as d:\RemoveComment.py
(4) Open cmd, input switch to (3) removecomment.py in the directory (here is d:\), input python removecomment.py d:\src d:\dst, enter
(5) The source code that removed the comment will be placed in the D:\DST directory

http://download.csdn.net/download/zp373860147/4361780

#Coding:utf-8ImportOSImportSYSdefdelcomment (SRC, DST): Fsrc= Open (src,'RB') FDST= Open (DST,'WB') out=[] State_normal=0 State_begin= 1state_line_comment= 2state_block_comment= 3State_end= 4 State=State_normal while1: Readinchar= Fsrc.read (1)        ifReadinchar = ="':             Break; ifstate = =State_normal:ifReadinchar = ='/': State=State_beginElse: Out.append (Readinchar)elifstate = =State_begin:ifReadinchar = ='/': State=state_line_commentelifReadinchar = ='*': State=state_block_commentElse: State=state_normal Out.append ('/'+Readinchar)elifstate = =state_line_comment:ifReadinchar = ='\ n': State=State_normalelifstate = =state_block_comment:ifReadinchar = ='*': State=State_endelifstate = =State_end:ifReadinchar = ='/': State=State_normal Readinchar= Fsrc.read (1)                 whileReadinchar = ='\ r' orReadinchar = ='\ n': Readinchar= Fsrc.read (1) Fsrc.seek (-1, 1)            Else: State=state_block_comment Fsrc.seek (-1, 1) Fdst.writelines (out) Fdst.flush () Fdst.close () Fsrc.close ( )defScandir (Srcpath, Dstpath):ifOs.path.isdir (srcpath): forFilesinchOs.listdir (Srcpath): Fsrc=os.path.join (Srcpath, files)ifOs.path.isfile (FSRC): Scandir (FSRC, Dstpath)Else: Fdst=os.path.join (Dstpath, files)if  notos.path.exists (FDST): Os.mkdir (FDST) scandir (FSRC, FDST)Else:        ifSrcpath.endswith (('. h','. C','. cpp','. HPP','. Jave'): Delcomment (Srcpath, Os.path.join (Dstpath, Os.path.basename (Srcpath)))if __name__=='__main__': Paramlen=Len (SYS.ARGV)ifParamlen!=3:        Print 'input parameter Error'Sys.exit (1) Srcpath= Sys.argv[1].rstrip ('\\'). Rstrip ('/')    Print 'Src_path:'+Srcpath Dstpath= Sys.argv[2].rstrip ('\\'). Rstrip ('/')    Print 'Dst_path:'+DstpathPrint 'Convert ...'Scandir (Srcpath, Dstpath)Print 'done!'

Volume delete C and C + + comments

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.