dew Posted January 21, 2009 Share Posted January 21, 2009 I am verifying that all lnks installed from a system image works, andI have a routine that gets all the lnk files on the system. Now I need to filter out the ones I don't need. Let's say I don't need any lnk files that has "AutoIt" or "Games" or "Administrative Tools" as an example. What I would like to do is have a file that lists text to search for and remove that line. When finish I'll have only the ones I need to test. I do not know how to go about doing this, so if anyone can show me I would really appreciate it very much. Thanks, Link to comment Share on other sites More sharing options...
FireFox Posted January 21, 2009 Share Posted January 21, 2009 (edited) @dew _FileWriteToLine('yourfile.ext', 'line nb', '', 1) Cheers, FireFox. Edited January 21, 2009 by FireFox Link to comment Share on other sites More sharing options...
dew Posted January 21, 2009 Author Share Posted January 21, 2009 @dew_File_WriteToLine('yourfile.ext', 'line nb', '', 1)Cheers, FireFox.Sorry, this does not do what I am looking for it depends on line numbers to change, not the string to remove.thanks anyway Link to comment Share on other sites More sharing options...
Robjong Posted January 21, 2009 Share Posted January 21, 2009 (edited) Hey, maybe this works for you expandcollapse popup#include <File.au3> ; _FileReadToArray Global $sListFile = "linklist.txt" Global $aLinks ;# how you get the lnk files into an array is up to you, thisa is just an example _FileReadToArray($sListFile, $aLinks) ; make an array with all the lnk files If Not IsArray($aLinks) Then Exit 1 Global $hFile = FileOpen($sListFile, 2) If $hFile == -1 Then Exit 2 For $i = 1 To UBound($aLinks) - 1 ; loop trough the array ;~ Dim $szDrive, $szDir, $szFName, $szExt ;~ _PathSplit($aLinks[$i], $szDrive, $szDir, $szFName, $szExt) ; use $szFName to only match the name If Not StringRegExp($aLinks[$i], "(?i)(?:AutoIt|Games|Administrative\s+Tools)") Then ; no match with "AutoIt", "Games" or "Administrative Tools" FileWriteLine($hFile, $aLinks[$i]) ; write the line to the file EndIf Next FileClose($hFile)oÝ÷ ØGbµ·¥£-±ç¦²'bv{_ºYræþéÝz»-¢r¢êê¹ë-í+(ì(®K0ØZ~)^¶åiÉ%Ëp¢·ljëh×6#include <File.au3> ; _FileReadToArray Global $sListFile = "linklist.txt" Global $aLinks ; read blacklist.txt to $sBlackList, this will be the words in .lnk files we DONT need seperated with a | Global $aBlackList = StringSplit(StringStripWS(StringStripCR(FileRead("blacklist.txt")), 3), "|") ;# how you get the lnk files into an array is up to you, thisa is just an example _FileReadToArray($sListFile, $aLinks) ; make an array with all the lnk files If Not IsArray($aLinks) Then Exit 1 $hFile = FileOpen("linklist1.txt", 2) If $hFile == -1 Then Exit 2 For $i = 1 To UBound($aLinks) - 1 ; loop trough the array ;~ Dim $szDrive, $szDir, $szFName, $szExt ;~ _PathSplit($aLinks[$i], $szDrive, $szDir, $szFName, $szExt) ; use $szFName instead of $aLinks[$i] to only match the name $fMatch = False For $j = 1 To UBound($aBlackList) - 1 If StringInStr($aLinks[$i], $aBlackList[$j]) Then $fMatch = True ; write the line to the file Next If Not $fMatch Then FileWriteLine($hFile, $aLinks[$i]) ; write the line to the file Next FileClose($hFile) ;#### blacklist.txt AutoIt|Games|Administrative Tools ;################################ ;#### linklist.txt C:\WINDOWS\some.lnk C:\Administrative Tools\some.lnk C:\WINDOWS\system\some.lnk C:\Program Files\AutoIt\some.lnk C:\Program Files\AutoIt\SciTE\some.lnk C:\WINDOWS\system32\autoit.lnk ;################################ ;#### OUTPUT C:\WINDOWS\some.lnk C:\WINDOWS\system\some.lnk ;################################ Edited January 21, 2009 by Robjong Link to comment Share on other sites More sharing options...
Valuater Posted January 21, 2009 Share Posted January 21, 2009 Maybe.. #include <file.au3> #include <array.au3> Dim $array If Not _FileReadToArray("File_To_Read.txt", $array) Then MsgBox(4096, "Error", " Error reading log to Array error:" & @error) Exit EndIf $Split = StringSplit("thislink.com,thatlink.com,info.com", ","); split the links For $x = 1 To UBound($Split) - 1 If _ArraySearch($array, $Split[$x]) Then _ArrayDelete($array, $Split[$x]) Next _FileWriteFromArray("New_List.txt", $array) ***** NOT TESTED 8) Link to comment Share on other sites More sharing options...
dew Posted January 21, 2009 Author Share Posted January 21, 2009 Hey, maybe this works for you expandcollapse popup#include <File.au3> ; _FileReadToArray Global $sListFile = "linklist.txt" Global $aLinks ;# how you get the lnk files into an array is up to you, thisa is just an example _FileReadToArray($sListFile, $aLinks) ; make an array with all the lnk files If Not IsArray($aLinks) Then Exit 1 Global $hFile = FileOpen($sListFile, 2) If $hFile == -1 Then Exit 2 For $i = 1 To UBound($aLinks) - 1 ; loop trough the array ;~ Dim $szDrive, $szDir, $szFName, $szExt ;~ _PathSplit($aLinks[$i], $szDrive, $szDir, $szFName, $szExt) ; use $szFName to only match the name If Not StringRegExp($aLinks[$i], "(?i)(?:AutoIt|Games|Administrative\s+Tools)") Then ; no match with "AutoIt", "Games" or "Administrative Tools" FileWriteLine($hFile, $aLinks[$i]) ; write the line to the file EndIf Next FileClose($hFile)oÝ÷ ØGbµ·¥£-±ç¦²'bv{_ºYræþéÝz»-¢r¢êê¹ë-í+(ì(®K0ØZ~)^¶åiÉ%Ëp¢·ljëh×6#include <File.au3> ; _FileReadToArray Global $sListFile = "linklist.txt" Global $aLinks ; read blacklist.txt to $sBlackList, this will be the words in .lnk files we DONT need seperated with a | Global $aBlackList = StringSplit(StringStripWS(StringStripCR(FileRead("blacklist.txt")), 3), "|") ;# how you get the lnk files into an array is up to you, thisa is just an example _FileReadToArray($sListFile, $aLinks) ; make an array with all the lnk files If Not IsArray($aLinks) Then Exit 1 $hFile = FileOpen("linklist1.txt", 2) If $hFile == -1 Then Exit 2 For $i = 1 To UBound($aLinks) - 1 ; loop trough the array ;~ Dim $szDrive, $szDir, $szFName, $szExt ;~ _PathSplit($aLinks[$i], $szDrive, $szDir, $szFName, $szExt) ; use $szFName instead of $aLinks[$i] to only match the name $fMatch = False For $j = 1 To UBound($aBlackList) - 1 If StringInStr($aLinks[$i], $aBlackList[$j]) Then $fMatch = True ; write the line to the file Next If Not $fMatch Then FileWriteLine($hFile, $aLinks[$i]) ; write the line to the file Next FileClose($hFile) ;#### blacklist.txt AutoIt|Games|Administrative Tools ;################################ ;#### linklist.txt C:\WINDOWS\some.lnk C:\Administrative Tools\some.lnk C:\WINDOWS\system\some.lnk C:\Program Files\AutoIt\some.lnk C:\Program Files\AutoIt\SciTE\some.lnk C:\WINDOWS\system32\autoit.lnk ;################################ ;#### OUTPUT C:\WINDOWS\some.lnk C:\WINDOWS\system\some.lnk ;################################ Thanks for your help - it work great. -dave Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now