Sign in to follow this  
Followers 0
goldenix

IniWrite Design help

1 post in this topic

#1 ·  Posted (edited)

Hi.

So This is a script, that searches for text inside the files, but...

This is How I want it to write the log file, But no mater how I try , its not happening...( See the Full GUI,code & sample files in the attachment, Thank you.)

=====================================================================
[@Scriptdir\Copy of New Text document.txt]
=====================================================================
line:  2=  appikene oi oi
line:  4=  appikene oiuy rteat .-,lgutd 5e5

=====================================================================
[@Scriptdir\New Text document.txt]
=====================================================================
line:  2=  appikene oi oi
line:  4=  appikene oiuy rteat .-,lgutd 5e5

EDIT:....it took time, but i Figured it out Hre is the full script...Btw i had to remove the previous lines cuz the editing system scrwed them up, so... :

#include <file.au3>
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 

HotkeySet('!1', "_Maximize")    ; ALT + 1 [^ Ctrl    ! Alt    + Shift    # Win]

    $I_read_extension = IniRead(@MyDocumentsDir & "\searchfilesfortext_config.ini",'Config','extension','')
    $I_read_texttosearch = IniRead(@MyDocumentsDir & "\searchfilesfortext_config.ini",'Config','texttosearch','')

#Region ### START Koda GUI section ### Form=
;=============================================================================
;GUI 1
;=============================================================================
$Mainwindow = GUICreate("Search_insidefiles", 258, 146, 455, 339)
$Label1 = GUICtrlCreateLabel("File Extension (No dot)", 15, 25, 110, 17)
$input_extension = GUICtrlCreateInput($I_read_extension, 15, 44, 65, 21)
$Label3 = GUICtrlCreateLabel("Search for:", 15, 79, 56, 17)
$input_searchfor= GUICtrlCreateInput($I_read_texttosearch, 15, 96, 225, 21)
$Button1 = GUICtrlCreateButton("Go babe", 152, 40, 89, 33, 0)
$Label2 = GUICtrlCreateLabel("", 175, 16, 70, 17)
$Label4 = GUICtrlCreateLabel("", 12, 125, 500, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;=============================================================================
;GUI Events
;=============================================================================
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_Maximize") 
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_Minimize") 
GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT")
GUICtrlSetOnEvent($Button1, "_Scan") 

;=============================================================================
;Functions
;=============================================================================
func _Minimize()
    GUISetState(@SW_HIDE, $Mainwindow)
EndFunc

func _Maximize()
    If WinActive("Search_insidefiles") Then
        GUISetState(@SW_HIDE, $Mainwindow) 
    Else
        GUISetState(@SW_SHOW, $Mainwindow) 
        GUISetState(@SW_RESTORE,$Mainwindow)
    EndIf
EndFunc

func _EXIT()
    Exit
EndFunc

Global $FileCount, $Filefound_Count

func _Scan()
Dim $FolderName = @ScriptDir ;lines tells us the folder to scan and initializes the file count
Dim $FileCount = 0
Dim $Filefound_Count = 0
FileDelete(@ScriptDir & "\Log.txt")


ScanFolder($FolderName)
GUICtrlSetData($Label2,'Done')
ToolTip('')
MsgBox(0,"Done","Folder Scan Complete." & @CRLF & @CRLF & $FileCount& "   Files Scanned" & @CRLF & $Filefound_Count& '   Times Found text'  )
If FileExists('Log.txt') Then ShellExecuteWait(@ScriptDir & "\Log.txt"); open log
IniWrite(@MyDocumentsDir & "\searchfilesfortext_config.ini",'Config','lastscriptdir','')
EndFunc
 
Func ScanFolder($SourceFolder)
    Local $Search
    Local $File
    Local $FileAttributes
    Local $FullFilePath
    $filepathcount = 1
    $search_for_text = GUICtrlRead($input_searchfor)
    $extension = '.' & GUICtrlRead($input_extension)
    GUICtrlSetData($Label2,'Working...')
    $Search = FileFindFirstFile($SourceFolder & "\*.*") ; searches all files
 
        While 1
            If $Search = -1 Then
                ExitLoop
            EndIf

            $File = FileFindNextFile($Search) ; start searching for next file
            If @error Then ExitLoop

            $FullFilePath = $SourceFolder & "\" & $File
            $FileAttributes = FileGetAttrib($FullFilePath)
                $cutfilepath = StringReplace($FullFilePath,@ScriptDir,'')   
                ToolTip($cutfilepath ,0 ,0)         
            
;=============================================================================
            If StringInStr($FileAttributes,"D") Then ; get file attribute & if its a folder = D then search it
                ScanFolder($FullFilePath)
            Else
;=============================================================================
                    If StringInStr($File, $extension) Then ; if file is *.php for example
;=============================================================================
                        Local $nArray
                        If Not _FileReadToArray($FullFilePath, $nArray) Then MsgBox(0,'','cant read to array file:' & @CRLF & $FullFilePath )
    ;~                  ;open file to search it if its the file we need
;=============================================================================
                            $file_open = FileOpen($FullFilePath, 0) ;0 = Read mode 
                            For $iCount = 1 To UBound($nArray) - 1
                                If $iCount = UBound($nArray) - 1 Then ExitLoop
;~ ----------------------------------------------------------------     

                                    If  StringInStr($nArray[$iCount],$search_for_text) Then ; if found the text in the file we search for 
                                        $Filefound_Count += 1
;~ ---------------------------------------------------------------- 
                                            $string_left1 = StringLeft($nArray[$iCount],1) ; get first char
                                            $count = 1
                                            While 1
                                                If $string_left1 = ' ' Then ; if first char is space

                                                    $string_trim_left = StringtrimLeft($nArray[$iCount],$count) ; cut the space
;~                                                  MsgBox(1,'', $string_trim_left)
                                                    
                                                    $string_left2 = StringLeft($string_trim_left,1) ; get trimmed linke first chat
                                                    If not StringInStr($string_left2,' ') Then ExitLoop ; if first char is not space                                                        
                                                    $count += 1
                                                Else
                                                    $string_trim_left = $nArray[$iCount] ; if first char is not space
                                                    ExitLoop
                                                EndIf
                                            WEnd    


;~                                      Hire we write the log file
;~ ----------------------------------------------------------------     
                                    $I_read_lastscriptdir = IniRead(@MyDocumentsDir & "\searchfilesfortext_config.ini",'Config','lastscriptdir','')
                                    $file_ = FileOpen(@ScriptDir & "\Log.txt", 1)

                                            If $cutfilepath <> $I_read_lastscriptdir Then ; if not equal then write folder path
                                                FileWrite($file_,@CRLF & "=====================================================================" & @CRLF)
                                                FileWrite($file_,'@Scriptdir' & $cutfilepath)
                                                FileWrite($file_,@CRLF & "=====================================================================" & @CRLF)
                                            EndIf
                                                FileWrite($file_,'line: | ' & $iCount & ' | ' & $string_trim_left & @CRLF); Write line
                                                
                                        IniWrite(@MyDocumentsDir & "\searchfilesfortext_config.ini",'Config','lastscriptdir',$cutfilepath)
                                    FileClose($file_)
;~ ----------------------------------------------------------------                                             IniWrite(@MyDocumentsDir & "\searchfilesfortext_config.ini",'Config','extension',GUICtrlRead($input_extension))
                                        IniWrite(@MyDocumentsDir & "\searchfilesfortext_config.ini",'Config','texttosearch',GUICtrlRead($input_searchfor))
                                    EndIf
;~ ----------------------------------------------------------------                         
                            Next
                            FileClose($file_open)   
;=============================================================================              
                    EndIf               
            $FileCount += 1 ; checkked files count +1   
            EndIf
        WEnd
    FileClose($Search)
EndFunc

 
While 1
Sleep(100)  
WEnd
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

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