Sign in to follow this  
Followers 0
kolinrp24

Comment Deleter v2

2 posts in this topic

#1 ·  Posted (edited)

i made this over night, it has checkboxes so u can delete comments like....

;one comment example

#comments-start

this is example 2

#comments-end

#cs example

number

3 #ce

it can also delete whitespaces

plz check it out

-kolin

p.s. if anyone wants one with comments describing everything, ask and i'll post it

#include <GuiConstants.au3>
#include <file.au3>
GUICreate("Comment Deleter", 371, 161, (@DesktopWidth-371)/2, (@DesktopHeight-161)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$Chec1 = GUICtrlCreateCheckbox("Delete comments begining with a semicolon?  (;)", 10, 40, 250, 20)
GUICtrlSetState(-1,IniRead(@scriptdir&"\comdel.ini","Options","chec1",1))
$Chec2 = GUICtrlCreateCheckbox("Delete comments in the form:  #comments-start.....#comments-end  ?", 10, 60, 350, 20)
GUICtrlSetState(-1,IniRead(@scriptdir&"\comdel.ini","Options","chec2",1))
$Chec3 = GUICtrlCreateCheckbox("Delete comments in the form:  #cs...#ce  ?", 10, 80, 350, 20)
GUICtrlSetState(-1,IniRead(@scriptdir&"\comdel.ini","Options","chec3",1))
$Chec4 = GUICtrlCreateCheckbox("Delete blank lines?", 10, 100, 250, 20)
GUICtrlSetState(-1,IniRead(@scriptdir&"\comdel.ini","Options","chec4",1))
$Continue = GUICtrlCreateButton("Continue...", 10, 130, 90, 20,$BS_DEFPUSHBUTTON )
$Exit = GUICtrlCreateButton("Exit", 140, 130, 90, 20)
$About = GUICtrlCreateButton("About", 270, 130, 90, 20)
$Header = GUICtrlCreateLabel("Comment Deleter v2", 10, 0, 350, 40)
GUICtrlSetFont(-1,25)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg=$Continue
            GUISetState(@SW_DISABLE,"Comment Deleter")
            IniWrite(@scriptdir&"\comdel.ini","Options","chec1",GUICtrlRead($Chec1))
            IniWrite(@scriptdir&"\comdel.ini","Options","chec2",GUICtrlRead($Chec2))
            IniWrite(@scriptdir&"\comdel.ini","Options","chec3",GUICtrlRead($Chec3))
            IniWrite(@scriptdir&"\comdel.ini","Options","chec4",GUICtrlRead($Chec4))
            Dim $comstart,$csce,$cscedel,$comstartdel,$whitedel,$delcom
            If $CmdLine[0] = 1 Then
                $file = $CmdLine[1]
            Else
                $file = FileOpenDialog("Open...", @MyDocumentsDir, "Text or autoit (*.txt;*.au3)", 1 + 2)
            EndIf
            If @error Then Exit
            $linenum = _FileCountLines($file)
            $tempfile = @TempDir & "\commentdeleter.au3"
            _FileCreate($tempfile)
            While 1
                ProgressOn("Comment Deleter", "0% completed.  Working...", "0 lines out of " & $linenum & " processed.",326,326, 16)
                WinActivate("Comment Deleter","0% completed.  Working...")
                For $i = 1 To $linenum
                    $line = FileReadLine($file, $i)
                    If @error = -1 Then 
                        ExitLoop
                    Else
                        $lineclear = StringStripWS($line, 8)
                        Select
                        Case StringIsSpace($line)=1 OR $line="" AND GUICtrlRead($Chec4)=1
                            $whitedel=$whitedel+1
                        Case StringLeft($lineclear,1)=";" AND GUICtrlRead($Chec1)=1
                            $delcom=$delcom+1
                        Case StringLeft($lineclear,15)="#comments-start" OR $comstart=1 AND GUICtrlRead($Chec2)=1
                            $comstart=1
                            $comstartdel=$comstartdel+1
                            If StringInStr($lineclear,"#comments-end")>0 Then $comstart=0
                        Case StringLeft($lineclear,3)="#cs" OR $csce=1 AND GUICtrlRead($Chec3)=1
                            $csce=1
                            $cscedel=$cscedel+1
                            If StringInStr($lineclear,"#ce")>0 Then $csce=0
                        Case Else
                            FileWriteLine($tempfile, $line)
                        EndSelect
                    EndIf
                    $per = Round(100 * $i / $linenum, 0)
                    ProgressSet($per, $i & " lines out of " & $linenum & " processed.", $per & "% completed.  Working...")
                Next
                ProgressSet("100",$linenum&" lines processed.", "100% completed.")
                Sleep(500)
                ProgressOff()
                Dim $a,$b,$c,$d
                _PathSplit ($file,$a,$b,$c,$d)
                MsgBox(0,"",$delcom+0&" comments deleted from script."&@CRLF&$comstartdel+0&" #comments-start...#comments-end comments deleted from script."&@CRLF&$cscedel+0&" #cs...#ce comments deleted from script."&@CRLF&$whitedel+0&" empty lines deleted from script.")
                $newfile=FileSaveDialog("Save edited script as...",$a&$b,"Text or Au3 (*.txt;*.au3)",16,$c&$d)
                FileCopy($tempfile,$newfile,1)
                Exit
            WEnd
        Case $msg=$About
            MsgBox(8256,"About","Comment Deleter v2" & @CRLF & "By Kolin Paulk" & @CRLF & "Tuesday, July 5, 2005")
        Case $msg=$Exit
            Exit
    EndSelect
WEnd
Exit
Edited by kolinrp24

Share this post


Link to post
Share on other sites



Adios, pesky comments.

(sorry, had to)

J


If I am too verbose, just say so. You don't need to run on and on.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0