Jump to content

from select 1 file, to select all files

Recommended Posts


i have a script that selects  a text file and deletes a line (text input required) in the text file selected

i have to make it remove all lines found on a file i name, toRemoveLines.txt

it has to remove lines from all text files found in a folder

this is the script that has to be modified

where it says "select file" it has to be "select folder"

where it says "line text input" it has to be all lines from a text file

#Include <File.au3>
Global $success = False
$file_name = FileOpenDialog("Select file", @ScriptDir, "All files (*.*)", 1+4)
$line_text_input = InputBox("Line's text", "Line must contain following text:", "line contains this text")
$file_count_lines = _FileCountLines($file_name)
for $i = 0 to $file_count_lines
    $Lines_text_output = FileReadLine($file_name, $i)
    if StringInStr($Lines_text_output, $line_text_input) then
        _FileWriteToLine($file_name, $i, "", 1)
        $success = True
if $success = True Then
    MsgBox(0, "Success", "Line has been deleted")
    MsgBox(0, "Failure", "Line wasn't found")


Share this post

Link to post
Share on other sites

@vin1 That is a great assessment of what you need - but please understand that this is not a forum where you put in an order and someone barfs up code for you. What you haven't provided us with is what you have tried on your own, and what trouble you are running into. Please do so, so we can assist in showing you how to improve your script.

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post

Link to post
Share on other sites

Not sure if this is what you meant, I've included two examples, just uncomment out one or the other, if you want to just replace lines with "" then use _Example1() or if you want to remove the lines then use _Example2().

#include <Array.au3>
#Include <File.au3>

Local $aSearchText ;~ Search Items
    _FileReadToArray(@ScriptDir & "\SearchText.txt", $aSearchText)
    If @error Then Exit MsgBox(4096, "Remove List", "Error: Reading SearchText.txt")

;~ Select Folder Path
Global $sFolderPath = FileSelectFolder("Select folder", @ScriptDir)
    If @error Then Exit MsgBox(4096, "Select Folder", "Error: No folder selected.")

;~ Folder Path Txt files to array
Global $aFileList = _FileListToArrayRec($sFolderPath, "*.txt", 1, 0, 0, 2)
    If @error Then Exit MsgBox(4096, "Folder List", "Error: Creating FileList.")

;~ _Example1()

;~ Overwrites lines with blank "" text, does not remove lines.
Func _Example1()
    Local $iLineCount
    ;~ Loop through each File Name
    For $i = 1 To $aFileList[0]
        $iLineCount = _FileCountLines($aFileList[$i])
        ;~ Loop through each file
        For $j = 0 To $iLineCount
            ;~ Loop through Search Text items
            For $k = 1 To $aSearchText[0]
                If StringInStr(FileReadLine($aFileList[$i], $j), $aSearchText[$k]) Then
                    ;~ Overwrite line data
                    _FileWriteToLine($aFileList[$i], $j, "", 1)

;~ Exampe2 Removes Lines from file
Func _Example2()
    Local $aFileRead, $aFindText, $hFileOpen, $bFindText = False
    ;~ Loop through each File Name
    For $i = 1 To $aFileList[0]
        _FileReadToArray($aFileList[$i], $aFileRead)
        If @error Then
            MsgBox(4096, "File Read to Array", "Error: Reading: " & $aFileList[$i] & " & to an Array")
        ;~ Loop through Search Text Array
        For $j = 1 To $aSearchText[0]
            ;~ Find all instances of Search Text item
            $aFindText = _ArrayFindAll($aFileRead, $aSearchText[$j])
            If @error Then ContinueLoop
            ;~ Loop through array and remove lines from the array
            For $k = UBound($aFindText) - 1 To 0 Step - 1
                _ArrayDelete($aFileRead, $aFindText[$k])
                $bFindText = True
        ;~ If replacements were made overwrite the file with the updated array data.
        If $bFindText Then
            $hFileOpen = FileOpen($aFileList[$i], 2)
            _FileWriteFromArray($hFileOpen, $aFileRead, 1)
            $bFindText = False


Share this post

Link to post
Share on other sites

@JLogan3o13 Sorry have insomnia and was feeling bored.

Share this post

Link to post
Share on other sites

@Subz Insomnia + bored <> Spon-feeds noobs.

Insomnia = time+fun

bored = search(new interest)

gl :shifty:

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

  • Similar Content

    • misioooo
      By misioooo
      I am writing some GUI and i need to use images as buttons, but with text on them (text is from INI file).
      Part with button looks like this:
      $ankieta1 = GUICtrlCreateButton($txtAnk1, 100,350,765,164) GUICtrlSetFont(-1, 22, 800, -1, "Arial") ;GUICtrlSetColor(-1,0xffffff) $hImageBtn_1 = _GUIImageList_Create(765, 164) _GUIImageList_AddBitmap($hImageBtn_1, "c:\path\to\ankieta_clean.bmp") _GUICtrlButton_SetImageList($ankieta1, $hImageBtn_1, 4) GUICtrlSetOnEvent(-1, "On_Ankieta1") The problem - if i uncomment GUICtrlSetColor, color of text changes, but button is just plain gray (no image). How i can change text color not touching image on a button here?
    • Epic007
      By Epic007
      Hey guys I'm stuck with a program.....I need a make an automation which copies text from a chat bot app and paste it in notepad to log the replies of my chat bot and to analyse stuff....a lil help pls
      Thanks in advance
    • nooneclose
      By nooneclose
      I need to send a string of text to this popup and click on the ok button to save it.
      Here is the code I have so far:
      ;Start IE Sleep(7000) $oIE = _IECreate("http://www.google.com") Sleep(500) _IELoadWait($oIE) $hIE = _IEPropertyGet($oIE, "hwnd") ; Get Handle of the IE window Sleep(500) WinSetState($hIE, "", @SW_MAXIMIZE) ;Wait for a browser page load to complete Sleep(3000) _IENavigate($oIE, "https://properURL.com") Sleep(8000) _IELoadWait($oIE) ;Attach to a browser control embedded in another window $oIE = _IEAttach("https://"properURL.com", url") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & ' Extended code: 0x' & Hex(@extended) & @CRLF) ;### Debug Console Sleep(2000) ;Get the title of the webpage ;Local $wTitle = _IEPropertyGet($oIE, "title") ;MsgBox($MB_SYSTEMMODAL, "Webpage title:", $wTitle) ;Clicks the new button Sleep(3000) _IEAction($nWorkOrderB, "focus") _IEAction($nWorkOrderB, "click") Sleep(5000) ;Store the Element names where the important data will be sent ;Store the long description button Local $wLongDButton = _IEGetObjById($oIE, "m65d795a4-img") ;Store the long Description field id Local $wComments = _IEGetObjById($oIE, "ma6499a9c-rte_iframe") ;Store the ok button id that is in the long description Local $wCommOk = _IEGetObjById($oIE, "m74031266-pb") ;******************************************************************************* ; Send the stored data to the proper field ;******************************************************************************* ;Click the long description button Sleep(300) _IEAction($wLongDButton, "focus") _IEAction($wLongDButton, "click") Sleep(300) ;Sends the Comments Sleep(500) _IEAction($wComments, "focus") _IEAction($wComments, "click") Sleep(500) _IEFormElementSetValue($wComments, "hello darkness my old friend") ;Click the ok button Sleep(500) _IEAction($wCommOk, "focus") _IEAction($wCommOk, "click") Sleep(500)  
      Here is the popup:

    • reida
      By reida
      Hello. Help to write the text.
      <textarea tabindex="4" class="js-input compose__labels__input" style="width: 407px; max-width: 413px;" wrap="off" autocomplete="off" data-original-name="To"></textarea>  I can not make.
      #include <IE.au3> $sLogin = 'adv' $iError = 1 $sUrl = 'https://......' $oIE = _IECreate($sUrl) ;;; _IELoadWait($oIE) $oLogin = _IEGetObjByName($oIE, "To") Sleep(7000) If IsObj($oLogin) Then _IEFormElementSetValue($oLogin, $sLogin) _IELoadWait($oIE) ; EndIf EndIf Through the selector it can be possible?
      #toolkit-154163367424641composeForm > div:nth-child(1) > div > div.compose-head__content.js-collapsed-off > div.compose-head__row-wrapper.compose-head__row-wrapper_to.js-row > div > div > div:nth-child(2) > div > div > div > textarea.js-input.compose__labels__input  
    • cramaboule
      By cramaboule
      Hi all,
      I was wondering if it is possible (and how) to put text on video on-the-fly (like VLC displays Title movie at the begining)
      and of course doing that in AutoIt
      Thanks in advance...