Jump to content
Sign in to follow this  

Select item from list and delete it from master list

Recommended Posts


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)
$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 )
    Return ( $_Array )
EndFunc ;==> _DeleteArrayElementWithStringInstr ( )

AutoIt 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  


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.