Jump to content

String question. How to find and destroy ?


Recommended Posts

Guys ! i have a result here which might or might not be exactly the same order each time or even have different paths.

C:\Users\Administrator\Desktop\System

C:\Users\Administrator\Desktop\System

C:\Users\Administrator\Desktop\StaticMeshes

C:\Users\Administrator\Desktop\StaticMeshes

C:\Users\Administrator\Desktop\StaticMeshes

C:\Users\Administrator\Desktop\StaticMeshes

C:\Users\Administrator\Desktop\StaticMeshes

C:\Users\Administrator\Desktop\System

C:\Users\Administrator\Desktop\Sounds

C:\Users\Administrator\Desktop\Sounds

C:\Users\Administrator\Desktop\Sounds

C:\Users\Administrator\Desktop\StaticMeshes

C:\Users\Administrator\Desktop\StaticMeshes

C:\Users\Administrator\Desktop\Maps

How do i use strings to search this and find similar once and if such found remove them ?

Link to comment
Share on other sites

Where is that list generated from, is it a text file ?, do you already have them stored in an array ? , are you generating that list yourself in a loop in your own autoit script ? Would need a bit more info to know how to tackle it.

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

its a TXT file stored in scriptdir

Its generated after loop exist or before each time single or multiple fileopendialog returns a value from different Dir's at different times.

Returned value stored into text file so it can then be used to search for files in those Dir's for matching extension..

Once those found they are moved to previously defined location.

$Line = "1"
$ReadPath = FileReadLine (@ScriptDir & "\UT2004CompressPaths.txt",$Line)
$UT2004search = FileFindFirstFile ($ReadPath & "\*")
While 1

    $UT2004searchreturn = FileFindNextFile ($UT2004search)
    If $UT2004searchreturn = "" Then
        Assign ("Line",+1)
        MsgBox(0,'',$Line & "Line ="& $ReadPath)
    Else
        $GetExt = StringRight ($UT2004searchreturn,3)
        If $GetExt = "uz2" Then
            MsgBox(0,'',"uz2")
            FileMove ($ReadPath & "\" & $UT2004searchreturn, @DesktopDir & "\" &$UT2004searchreturn)
            MsgBox(0,'',$UT2004searchreturn)
        EndIf
    EndIf
WEnd

this code works to move files out of there but its not changing the line from which to read next directory to search from for uz2 format files.

Having same directories listed in one txt file is only half of the problem i hope with your help can be solved.

I still need to figure out why when i place FileReadLine in a loop with $line as the line to read (instead of before loop) its not working at all.

Thanks man, i really appreciate you helping me out 2nd time today in just a few minutes :mellow:

Thank god i have no college today so i can fix that damn problem i left out before releasing the app a while ago as a contribution to UT2004 UT3 community :party:

Dont rush answering, i still have half bag of barbecue chips and 4 bottles of Blue Moon beer to help me get through the day :P

Edited by madasraka
Link to comment
Share on other sites

Hope you enjoyed your chips n beer.

This should hopefully do what you want, uncomment the filemove line and comment or delete the msgbox after it, once you've run it and seen it say where it will take the file from and move it to as i dont have the files to test it properly.

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

Global $hTxtFilePath = @ScriptDir & "\UT2004CompressPaths.txt", $aListAll, $aListUnique, $aListMove

If Not _FileReadToArray($hTxtFilePath, $aListAll) Then
    MsgBox(0, "Error!", "Failed to read file path: " & $hTxtFilePath & " into an array")
    Exit
EndIf
$aListUnique = _ArrayUnique($aListAll, 1, 1)
$aListAll = 0
If IsArray($aListUnique) Then
    For $i = 1 To $aListUnique[0] Step 1
        $aListMove = _FileListToArray($aListUnique[$i], "*.uz2", 1)
        If IsArray($aListMove) Then
            For $i2 = 1 To $aListMove[0] Step 1
;~              FileMove($aListUnique[$i] & "\" & $aListMove[$i2], @DesktopDir & "\" & $aListMove[$i2])
                MsgBox(0,"Test", "Would move: " & $aListUnique[$i] & "\" & $aListMove[$i2] & @CR & "To: " & @DesktopDir & "\" & $aListMove[$i2])
            Next
        EndIf
    Next
Else
    MsgBox(0, "Error!", "Failed to create unique array")
EndIf
$aListUnique = 0
$aListMove = 0
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Ended up doing this instead

$Line = '1' ;this changes in order to search next line instead of same one again.
$Extention = ".uz2"
    While 1
        $dirNext = FileReadLine (@ScriptDir & "\UT2004CompressPaths.txt",$Line)
        If $dirNext = "" Then
            ExitLoop
        Else
            $fSearch = FileFindFirstFile ($dirNext & "\*.uz2")
            $sSearchReturn = FileFindNextFile ($fSearch)
            $sExtension = StringRight ($sSearchReturn,3)
            If $sExtension = "" Then
                ;MsgBox(0,'',@ScriptLineNumber & " "& $dirNext)
                Assign ("Line",Number ($Line+1)) ;changed to search next line of the text file which gives path to search for extension.
            ElseIf $sExtension = "uz2" Then
                While 1
                    $dirNextAgain = FileReadLine (@ScriptDir & "\UT2004CompressPaths.txt",$Line)
                    $fSearchAgain = FileFindFirstFile ($dirNextAgain & "\*.uz2")
                    $sSearchReturnAgain = FileFindNextFile ($fSearchAgain)
                    $sExtensionAgain = StringRight ($sSearchReturnAgain,3)
                    If $sExtensionAgain = "uz2" Then
                        FileMove ($dirNextAgain & "\" & $sSearchReturnAgain, $UT2004ResultPath, 1)
                    ElseIf $sExtensionAgain = "" Then
                        Exitloop
                    EndIf
                WEnd
                ;MsgBox(0,'',@ScriptLineNumber)
            Else
                ;Nothing, continue search
            EndIf
        EndIf
    WEnd
.

Its not removing same lines if found, instead it goes over all of them. There wont me many anyway but because of your example i can take care of them later if needed.

Now thatks to you i was able to convert lines :

"C:\Users\Administrator\Desktop\Textures\Apoclypstex.utx"

to

C:\Users\Administrator\Desktop\Textures

.

but how do i convert this (returned by guictrlread):

"C:\Users\Administrator\Desktop\Textures\Riptex.utx"

"C:\Users\Administrator\Desktop\Textures\Stormtex.utx"

"C:\Users\Administrator\Desktop\Textures\Urotex.utx"

"C:\Users\Administrator\Desktop\Textures\VCTFBattlegroundTexes.utx"

into this ?

C:\Users\Administrator\Desktop\Textures

C:\Users\Administrator\Desktop\Textures

C:\Users\Administrator\Desktop\Textures

C:\Users\Administrator\Desktop\Textures

Sorry to bugging you this much.

Am sure if i would spend more time i would find the answer, but my time is short and i need to study for school tomorrow soon.

Thanks for ur help :mellow:

Edited by madasraka
Link to comment
Share on other sites

$var = "C:\Users\Administrator\Desktop\Textures\VCTFBattlegroundTexes.utx"

ConsoleWrite(StringLeft($var, StringInStr($var, '\', 0, -1) - 1) & @LF)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Man ! Thanks.

I had

StringLeft ($String ,StringInStr ($String ,'\'))

and could not tell why it didn't work. It looked OK to me :mellow:

Thanks for

StringLeft ($String ,StringInStr ($String ,'\', 0, -1) - 1)

Problem with this is that GUICTRLREAD returns 2 or many lines so that using this example

does not remove for all lines but last

Edited by madasraka
Link to comment
Share on other sites

Ok so let's adapt this:

$var =  "C:\Users\Administrator\Desktop\Textures\Riptex.utx" & @CRLF & _
        "C:\Users\Administrator\Desktop\Textures\Stormtex.utx" & @CRLF & _
        "C:\Users\Administrator\Desktop\Textures\Administrator\Desktop\Textures\Administrator\Desktop\Textures\Urotex.utx" & @CRLF & _
        "C:\Users\Administrator\Desktop\Textures\VCTFBattlegroundTexes.utx"

ConsoleWrite(StringRegExpReplace($var, "(?m)^(.*?)(?:\\[^\\$]*)($)", "$1$2") & @LF)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...