Jump to content

search compare and sort file's name


Recommended Posts

Hello,

I'm trying to use Autoit to save me (and others users) days of work.

I must say I'm a newbie with autoit :">

I need to open a software with a particular file and apply a "patch" on this file

This part of the script is already working

The second part is more difficult to me, here it is what I want to do

- select a folder and search for all the file with the 'gig' extension (the "main" file)

- select a folder and search for all the file with the 'art' extension (the "patch")

Let's say I will find

aaaaa.gig

bbbbbbb.gig

ccccccccccc.gig

the patch's file will have the same name with some character added to the right, like this :

ccccccccccc_123.art

aaaaa_12.art

bbbbbbb_19.art

So, after searching all these files, I need to compare and sort them to be able to launch the software with the correct "main" and "patch" file.

I checked the FileSearch function from ezzetabi for searching the files, but I don't really know which function is better to compare and sort the file's name.

Any advice ?

btw : perhaps Autoit isn't a correct solution to do this. I say "correct" because it doesn't need to be the best solution as I don't know another language.

Thanks in advance

Link to comment
Share on other sites

Hello,

The second part is more difficult to me, here it is what I want to do

- select a folder and search for all the file with the 'gig' extension (the "main" file)

- select a folder and search for all the file with the 'art' extension (the "patch")

Let's say I will find

aaaaa.gig

bbbbbbb.gig

ccccccccccc.gig

the patch's file will have the same name with some character added to the right, like this :

ccccccccccc_123.art

aaaaa_12.art

bbbbbbb_19.art

So, after searching all these files, I need to compare and sort them to be able to launch the software with the correct "main" and "patch" file.

I checked the FileSearch function from ezzetabi for searching the files, but I don't really know which function is better to compare and sort the file's name.

Any advice ?

Thanks in advance

<{POST_SNAPBACK}>

I'm not certain if this is exactly what you are looking for. If it's not, perhaps it will give an idea.

$sAllGIG = ""
$sAllART = ""
$sOutNameGIG = @tempdir & "\Temporary-GIG.txt"
$sOutNameART = @tempdir & "\Temporary-ART.txt"

$sFolder = FileSelectFolder("Select the folder to search with the GIG and ART files", "c:\", 0, "c:\")

If $sFolder <> "" Then
  ; Get a list of GIG files.
   RunWait(@comspec & ' /c dir "' & $sFolder & '\*.GIG" /b/oN/s >"' & $sOutNameGIG & '"')
   Sleep(500)
  ; Get a list of ART files.
   RunWait(@comspec & ' /c dir "' & $sFolder & '\*.ART" /b/oN/s >"' & $sOutNameART & '"')
   Sleep(500)
  ; If the output file was created, read each line to get the sub-directory name to process.
   If FileExists($sOutNameGIG) And  FileExists($sOutNameART) And FileGetSize($sOutNameGIG) > 0 And FileGetSize($sOutNameART) > 0 Then
     ; Get the .GIG filenames into an AutoIt array.
      $hFile = FileOpen($sOutNameGIG, 0)
      While 1
         $sThisFile = FileReadLine($hFile)
         If @error = -1 Then ExitLoop
        ; Remove the .GIG extension
         $sAllGIG = $sAllGIG & "|" & StringLeft($sThisFile, Stringlen($sThisFile) - 4)
      WEnd
      FileClose($sOutNameGIG)
     ; Convert the GIG files to an array.
      $aAllGIG = StringSplit(StringMid($sAllGIG, 2), "|")
      Sleep(200)
      
     ; Get the .ART filenames into an AutoIt delimited string.
      $hFile = FileOpen($sOutNameART, 0)
      While 1
         $sThisFile = FileReadLine($hFile)
         If @error = -1 Then ExitLoop
        ; Remove the .GIG extension
         $sAllART = $sAllART & "|" & StringLeft($sThisFile, Stringlen($sThisFile) - 4)
      WEnd
      $sAllART = $sAllART & "|"
      FileClose($sOutNameART)
      Sleep(200)
      
     ; See if there is both a GIG and an ART file in the same folder.
      For $i = 1 to $aAllGIG[0]
         $sThisFile = $aAllGIG[$i]
         If StringInStr($sAllART, "|" & $sThisFile & "|") > 0 Then
;~ This message box is just for demonstration.  Replace with the code you need to launch the software.
MsgBox(4096, "xxx3.", $sThisFile & ".GIG has a corresponding .ART file.")
         EndIf
      Next
      
     ;; Clean up.
;~    FileDelete($sOutNameGIG)
;~    FileDelete($sOutNameART)
   Else
      MsgBox(4096, "No files found", "No GIG and/or ART files were found in folder " & $sFolder)
   EndIf
EndIf

Phillip

Link to comment
Share on other sites

Many thanks for your code !

too bad, the search function was already ok when I read your answer... :">

Now, I have an array [x lines][6] with all the files path, the sorted, unsorted.... files

I want to view the array content in several Listview but I have a problem :

"$mylist" & $i return a correct value ($mylist0 to... $mylist5) but the GuiCtrlCreateListViewItem return 0.

So the listview is empty

I don't know where is my mistake

GUICreate("Name to be set", 1265, 600) 

; I define 1 Listview for each column of the array
$mylist0 = GUICtrlCreateListView("Gig", 5, 5, 200, 550)
$mylist1 = GUICtrlCreateListView("Art", 210, 5)
$mylist2 = GUICtrlCreateListView("Sorted Gig", 415, 5)
$mylist3 = GUICtrlCreateListView("Sorted Art", 620, 5)
$mylist4 = GUICtrlCreateListView("Unaffected Gig", 825, 5)
$mylist5 = GUICtrlCreateListView("Unaffected Art", 1030, 5)

; Loops for populate the listviews :
; $i is the column number
; $j is the row number

For $i = 0 To UBound($array, 2) - 1
    For $j = 0 To $array[0][$i]
        GUICtrlCreateListViewItem($array[$j][$i], "$mylist" & $i)
    Next
Next

Best regards,

Link to comment
Share on other sites

You can't join variables like you are doing with "$mylist" & $i. Add the control ID's in an array like...

Dim $mylist[6]

$mylist[0] = GUICtrlCreateListView("Gig", 5, 5, 200, 550)
$mylist[1] = GUICtrlCreateListView("Art", 210, 5)
$mylist[2] = GUICtrlCreateListView("Sorted Gig", 415, 5)
$mylist[3] = GUICtrlCreateListView("Sorted Art", 620, 5)
$mylist[4] = GUICtrlCreateListView("Unaffected Gig", 825, 5)
$mylist[5] = GUICtrlCreateListView("Unaffected Art", 1030, 5)

Edit: I was right damnit. Look at the above.

Edited by Burrup

qq

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...