Jump to content

comment deleter


kolinrp24
 Share

Recommended Posts

this script removes any comments as long as the only thing on the line is a comment.

its very good for decreasing the size of a script that has been decompiled.

i hope u find it useful

-kolin

---------------------------------------START------------------------------------------------

#include <file.au3>

If $CmdLine[0] = 1 Then

$file = $CmdLine[1]

Else

$file = FileOpenDialog("Open...", @MyDocumentsDir, "Text or autoit (*.txt;*.au3)", 1 + 2)

EndIf

$commentsdeleted=0

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

_FileCreate(@TempDir&"\commentdeleter.au3")

$CountLines = _FileCountLines($file)

While 1

ProgressOn("Comment Deleter", "0 out of "&$CountLines&" lines processed", "0 percent")

For $i=1 to $CountLines

$chars = FileReadline($file,$i)

If @error = -1 Then ExitLoop

$char=StringStripWS($chars,8)

$com=StringLeft($char,1)

$perc=Round(100*$i/$CountLines,0)

ProgressSet($perc,$i&" out of "&$CountLines&" lines processed",$perc&" percent completed")

If $com=";" Then

$commentsdeleted=$commentsdeleted+1

Else

FileWriteLine(@TempDir&"\commentdeleter.au3",$chars)

EndIf

Next

Sleep(750)

ProgressOff()

MsgBox(0,"",$commentsdeleted&" comments deleted")

FileCopy(@TempDir&"\commentdeleter.au3",$file,1)

ExitLoop

WEnd

---------------------------------------END------------------------------------------------

Edited by kolinrp24
Link to comment
Share on other sites

But getting people to include comments is a good thing, even when they are your own.  Go back in 2 years, and those comments are priceless.

<{POST_SNAPBACK}>

oh, i know that, but i made this mainly for when decompiling scripts, for example: the other day i decompiled a script that requires beta, so that anyone could use it. (it has all of the #include stuff in it) but the comments that the decompiler added made it have 3215 lines in it, after i ran my comment deleter cscript, it only had 1868 lines. its still big, but not as much.

UPDATE: the last line in this script: "FileClose($file)" needs to be deleted, sorry for the inconvenience

Link to comment
Share on other sites

But getting people to include comments is a good thing, even when they are your own.  Go back in 2 years, and those comments are priceless.

<{POST_SNAPBACK}>

2 years? Try 2 hours... if I'm lucky...
Link to comment
Share on other sites

Cool. Just tried it on a script i decompiled and it deleted the comments added by exe2aut.

Good Job. :)

I have a suggestion though.

Add command line support like this

If $CmdLine[0] = 1 Then
    $File = $CmdLine[1]
Else
    $File = FileOpenDialog("Open...", @MyDocumentsDir, "Text or autoit (*.txt;*.au3)", 1 + 2)
EndIf
$commentsdeleted = 0
; Check if file opened for reading OK
If $File = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
_FileCreate(@TempDir & "\commentdeleter.au3")
$CountLines = _FileCountLines($File)
While 1
    ProgressOn("Comment Deleter", "0 out of " & $CountLines & " lines processed", "0 percent")
    For $i = 1 To $CountLines
        $chars = FileReadLine($File, $i)
        If @error = -1 Then ExitLoop
        $char = StringStripWS($chars, 8)
        $com = StringLeft($char, 1)
        $perc = Round(100 * $i / $CountLines, 0)
        ProgressSet($perc, $i & " out of " & $CountLines & " lines processed", $perc & " percent completed")
        If $com = ";" Then
            $commentsdeleted = $commentsdeleted + 1
        Else
            FileWriteLine(@TempDir & "\commentdeleter.au3", $chars)
        EndIf
    Next
    Sleep(750)
    ProgressOff()
    MsgBox(0, "", $commentsdeleted & " comments deleted")
    FileCopy(@TempDir & "\commentdeleter.au3", $File, 1)
    ExitLoop
WEnd

With this you can drag and drop scripts onto the exe if it is compiled and if you just click it the file open dialog pops up.

Edited by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...