Jump to content
Sign in to follow this  
seandisanti

It's been done before, but not lately...

Recommended Posts

seandisanti

***comments about the script***

just include it and call it with the name of an .au3 file. pass full path or not at your discretion. It will remove blank lines and comments, including block (#cs - #ce) comments, creating a new script in place of the old one, and save the old one in the same place with a .old extension. I didn't put any real error checking in it, as far as checking if file exists or anything, but because of the way it's written, it shouldn't do anything but crash if you give it a nonexistant file. Oh yeah, beta is required.

#include<file.au3>
Func ScriptStripNonCode($Script)
    $path = ""
    $pathend = 0
    If StringInStr($aScript, "\") Then
        For $x = 0 To StringLen($Script)
            If StringMid($Script, StringLen($Script) - $x, 1) = "\" Then
                $path = StringLeft($Script, StringLen($Script) - $x)
                $pathend = StringLen($Script) - $x
                $Script = StringRight($Script, $x)
                ExitLoop
            EndIf
        Next
    EndIf
    If StringLen($path) Then
        FileCopy($path & $Script, $path & StringLeft($Script, StringLen($Script) - 4) & ".old")
        $Script = $path & $Script
    Else
        FileCopy($Script, StringLeft($Script, StringLen($Script) - 4) & ".old")
    EndIf
    Dim $source
    _FileReadToArray($Script, $source)
    FileDelete($Script)
    For $z = 1 To $source[0]
        $tmp = $z
        Select
            Case StringInStr($source[$z], ";")
                If StringRight($source[$z], 1) = "_" Then
                    Do
                        $tmp = $tmp + 1
                    Until StringRight($source[$tmp], 1) <> "_"
                EndIf
                $source[$z] = StringLeft($source[$z], StringInStr($source[$z], ";") - 1)
                For $y = $z + 1 To $tmp
                    $source[$y] = ""
                Next
                $z = $tmp
            Case StringInStr(StringLower($source[$z]), "#cs")
                Do
                    $tmp = $tmp + 1
                Until StringInStr(StringLower($source[$tmp]), "#ce")
                For $y = $z To $tmp
                    $source[$y] = ""
                Next
                $z = $tmp
        EndSelect
        If StringLen(StringStripWS($source[$z], 8)) Then FileWriteLine($Script, $source[$z])
    Next
EndFunc

forgot to code block it the first time.

Edited by cameronsdad

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.