Jump to content

Removing Text From A List

Recommended Posts

This is what I have. I am opening the file in notepad. Does AutoIt care about the square thingys? If not, then it's not big deal and it's working great. I just don't know if they mess up the line count or not.

Func DelName ()

  Local $A, $I, $File, $Line

    $NumberOfNames = IniRead ($SettingsFile, 'Settings', 'NumberOfNames', "ERROR")
    $RemName = InputBox ("Delete Name", "Enter the name to be deleted:", "")

      $Count = 0

        $FileHandle = FileOpen ("NameList.txt", 0)

          If $File = -1 Then
            MsgBox (0, "Error", "Unable to open file.")

        $File2 = FileOpen ("TempNameList.txt", 2)

          If $File2 = -1 Then
           MsgBox (0, "Error", "Unable to open file.")

  While 1

    $SearchLine = FileReadLine ($FileHandle)

      If @error = -1 Then ExitLoop
        If $SearchLine <> "" Then
          If $SearchLine <> $RemName Then
            If $count = 0 Then 
              FileWrite ($File2, $SearchLine)

              FileWrite ($File2, @CRLF&$SearchLine)

     $Count = $Count + 1
            $Out = MsgBox (4, $SearchLine &" found","Delete?")
              If $out=7 Then

                If $Count = 0 Then 
                  FileWrite ($File2, $SearchLine)
                  FileWrite ($File2, @CRLF & $SearchLine)

     $Count = $Count + 1



FileClose ($FileHandle)
FileClose ($File2)
FileCopy ("TempNameList.txt", "NameUpList.txt", 1)
FileDelete ("TempNameList.txt")

$NumberOfNames = $Count
IniWrite ($SettingsFile, 'Settings', 'NumberOfNames', $NumberOfNames)


A little reading goes a long way. Post count means nothing.

Link to post
Share on other sites

Yes, the boxes matter, but...

This script will remove any extra returns, and if you were useing @lf, then AutoIt would read it as a line(or @cr or @CRLF), and if empty, it would remove it, if not, it would count it, so I guess the answer is it doesn't matter.

If you are getting other boxes (any ASC code that doesn't display), then there might be a problem.

Later on, if you wish to use part of a name (say you wanted to do this with Email addresses and are a bit lazy, change the if statement, as in a partial match. Ex:

If StringInStr(" " & $SearchLine,$RemName)=0 Then

This basically will find part of the Name. It will still ask you to confirm delete each time it finds a partial match.

edit... if it doesn't find any Part of the string, It returns 0.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to post
Share on other sites

Just for learnings sake here is my code Broken Down with comments added.

I really don't know what this does but you have it so I kept it =)

Local $File

This gets the name from the input box and then checks if the user hits cancel if they do then it returns back to the part in the script where the function was ran and returns the value zero.

So if you did

$CheckValue = DelName()

CheckValue would be 1 if it worked correctly and 0 if it didn't.

$RemName = InputBox ("Delete Name", "Enter the name to be deleted:", "")
   If @Error Then Return(0)

@Comspec is the dos prompt.

/c is to close the dos prompt after it is finished.

find is a dos command that seraches through a file.

/V is to show all values not containing a string

/I is for case insensitive search

"$Remname" is to search for the name from the input box

"$File" is the file to search

> @Tempdir.... is where to output the file

@SW_HIDE is to not show the dos box

RunWait(@Comspec & ' /c find /V /I "' & $RemName '" ' & $File & ' > ' & @Tempdir & '\TempOutput.txt',"",@SW_Hide)

Same as above but.

/C is to get the number of lines with a certain text.

I just switched from /I to /V this should help it now will search for all the lines not containing "ajdjakflj" which should be all of them. Unless your people have very strange names. :whistle:

RunWait(@Comspec & ' /c find /C /V "ajdjakflj" ' & @Temp & '\TempOutput.txt > ' & @Temp & 'TempOutput2.txt',"",@SW_Hide)

Opens the file with the number of lines and then reads line 2 then closes it and deletes it.

$FileHandle = FileOpen(@Temp & '\TempOutput2.txt',0)

   $ReadLine = FileReadLine($FileHandle,2)


   FileDelete(@Temp & '\TempOutput2.txt')

This will take the line read and splits it up into an array with the colon.

So the line read looks like

---------------Test.txt: 54

So $SplitValue[1] will equal ------------Test.txt and

$SplitValue[2] will equal 54

$SplitValue = StringSplit($Readline,":")

It then chages the 54 from a string to a number and assigns that to the variable $NumberOfNames

$NumberOfNames = Number($SplitValue[2])

It now moves or cuts the output file that I had when outputting all the names except the one you wanted to remove and pastes it over the old file with the list of names.

FileMove(@Temp & '\TempOutput.txt',$File,1)

Writes the number to your ini file

IniWrite ($SettingsFile, 'Settings', 'NumberOfNames', $NumberOfNames)

Then returns 1 for success


Hope this is helpful


Link to post
Share on other sites

here is an interesting way to see all the secondary command interpreter's command lines B)

run(@comspec & ' /c ' & @comspec & ' /? > c:\comspec.txt')

I thought it just looks funny. And it might surprise you that this will output 170+ lines.

I unfortunatly need to look at DOS help files to remember all thier command line options. I had way too many versions of DOS, DrDos, 4Dos, MsDos, IBMDos, OS2 command lines, Unix commandline, etc... besides the old apple, commador and other old OSs. ahh memories :whistle:

AutoIt3, the MACGYVER Pocket Knife for computers.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...