Sign in to follow this  
Followers 0
millisys

Select item from list and delete it from master list

3 posts in this topic

Hello, I am trying to write a script that will retrieve lines from a text file so that I may select one, and then remove that item from the text list. If there were originally 20 lines in the text file, there would then be only 19, and so forth. What I have so far is really clunky and does not remove the line. I am hoping there is something more elegant that this:

#include <Array.au3>

$foldernames = fileread("c:\foldernames.txt")
$array = StringSplit($foldernames, @lf)
_ArrayDisplay($array)
$label = clipget()
$label = stringtrimleft($label, StringInStr($label, '|'))
$text = StringRegExpReplace($foldernames, $label,"")

Thank you for your help

Share this post


Link to post
Share on other sites



To read the file to an array you can use _FileReadToArray. Once the lines are in the array you can edit/delete as needed. Then you can write back to the file with _FileWriteFromArray.

Share this post


Link to post
Share on other sites

Try this

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

Global $_Array

$_ItemToRemove = 'Item'
$_TxtFilePath = 'c:\foldernames.txt'
_FileReadToArray ( $_TxtFilePath, $_Array )
$_Array = _DeleteArrayElementWithStringInstr ( $_Array, $_ItemToRemove )
_FileWriteFromArray ( $_TxtFilePath, $_Array, 1 )
ShellExecute ( $_TxtFilePath )

Func _DeleteArrayElementWithStringInstr ( $_Array, $_String )
    Local $_Item
    For $_Element In $_Array
        If StringInStr ( $_Element, $_String ) <> 0 Then
            _ArrayDelete ( $_Array, $_Item )
        Else
            $_Item+=1
        EndIf
    Next
    Return ( $_Array )
EndFunc ;==> _DeleteArrayElementWithStringInstr ( )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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