Jump to content

_ArraySearch not functioning well


mlloz
 Share

Recommended Posts

hello all,

the _ArraySearch here always returns -1..

whats wrong with this code please?

$FrstArray = _FileListToArray($SrcFoldr)
$ScndArray = _FileListToArray($DstFoldr)

For $item In $FrstArray
    $vValue = StringReplace($item, 'jpg', 'flv')
    $v = _ArraySearch($ScndArray, $vValue, 0, 0, 0, 1)
    If Not @error Then
        FileMove($SrcFoldr & '\' & $FrstArray[$v], $DstFoldr)
    EndIf
Next
Link to comment
Share on other sites

  • Developers

hello all,

the _ArraySearch here always returns -1..

whats wrong with this code please?

What is the exact content of the 2 arrays?

copy the value of a couple entries manually into he array and post a snippet we can test with.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

this is the full code

where both of Folder1 & Folder2 contains the same filenames but with different extensions

Folder1 have more files, this script should move from Folder1 to Folder2 if the filename

is matched in both folders regardless of the extension

#Include <File.au3>
#Include <Array.au3>
$SrcFoldr = 'D:\Folder1'
$DstFoldr = 'D:\Folder2'

$FrstArray = _FileListToArray($SrcFoldr)
$ScndArray = _FileListToArray($DstFoldr)

For $item In $FrstArray
    $vValue = StringReplace($item, 'jpg', 'flv')
    $v = _ArraySearch($ScndArray, $vValue, 0, 0, 0, 1)
    If Not @error Then
        FileMove($SrcFoldr & '\' & $FrstArray[$v], $DstFoldr)
    EndIf
Next
Link to comment
Share on other sites

  • Developers

I hear you and understood that this is the intent...but obviously do not know the exact info that will be stored in the 2 arrays so do yourself a favor and list them and manually put them in this test script so we can test too.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

sorry for late

here it is

Local $FrstArray[32] = [ _
'King (1).jpg', _
'King (10).jpg', _
'King (11).jpg', _
'King (12).jpg', _
'King (13).jpg', _
'King (14).jpg', _
'King (15).jpg', _
'King (16).jpg', _
'King (17).jpg', _
'King (18).jpg', _
'King (19).jpg', _
'King (2).jpg', _
'King (20).jpg', _
'King (21).jpg', _
'King (22).jpg', _
'King (23).jpg', _
'King (24).jpg', _
'King (25).jpg', _
'King (26).jpg', _
'King (27).jpg', _
'King (28).jpg', _
'King (29).jpg', _
'King (3).jpg', _
'King (30).jpg', _
'King (31).jpg', _
'King (32).jpg', _
'King (4).jpg', _
'King (5).jpg', _
'King (6).jpg', _
'King (7).jpg', _
'King (8).jpg', _
'King (9).jpg']

Local $ScndArray[16] = [ _
'King (1).flv', _
'King (10).flv', _
'King (11).flv', _
'King (12).flv', _
'King (13).flv', _
'King (2).flv', _
'King (20).flv', _
'King (27).flv', _
'King (28).flv', _
'King (30).flv', _
'King (31).flv', _
'King (5).flv', _
'King (6).flv', _
'King (7).flv', _
'King (8).flv', _
'King (9).flv']
Link to comment
Share on other sites

  • Developers

Ok, so when I merge the 2 and run it, it looks like this works fine.

#Include <File.au3>
#Include <Array.au3>
$SrcFoldr = 'D:\Folder1'
$DstFoldr = 'D:\Folder2'
Local $FrstArray[32] = [ _
'King (1).jpg', _
'King (10).jpg', _
'King (11).jpg', _
'King (12).jpg', _
'King (13).jpg', _
'King (14).jpg', _
'King (15).jpg', _
'King (16).jpg', _
'King (17).jpg', _
'King (18).jpg', _
'King (19).jpg', _
'King (2).jpg', _
'King (20).jpg', _
'King (21).jpg', _
'King (22).jpg', _
'King (23).jpg', _
'King (24).jpg', _
'King (25).jpg', _
'King (26).jpg', _
'King (27).jpg', _
'King (28).jpg', _
'King (29).jpg', _
'King (3).jpg', _
'King (30).jpg', _
'King (31).jpg', _
'King (32).jpg', _
'King (4).jpg', _
'King (5).jpg', _
'King (6).jpg', _
'King (7).jpg', _
'King (8).jpg', _
'King (9).jpg']

Local $ScndArray[16] = [ _
'King (1).flv', _
'King (10).flv', _
'King (11).flv', _
'King (12).flv', _
'King (13).flv', _
'King (2).flv', _
'King (20).flv', _
'King (27).flv', _
'King (28).flv', _
'King (30).flv', _
'King (31).flv', _
'King (5).flv', _
'King (6).flv', _
'King (7).flv', _
'King (8).flv', _
'King (9).flv']

;~ $FrstArray = _FileListToArray($SrcFoldr)
;~ $ScndArray = _FileListToArray($DstFoldr)

For $item In $FrstArray
    $vValue = StringReplace($item, 'jpg', 'flv')
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $vValue = ' & $vValue & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    $v = _ArraySearch($ScndArray, $vValue, 0, 0, 0, 1)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $v = ' & $v & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
;~     If Not @error Then
;~         FileMove($SrcFoldr & '\' & $FrstArray[$v], $DstFoldr)
;~     EndIf
Next

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

do you know what...

for these folders it worked fine, and for other folders it won't even match any file.

i've tried to change the folder names and it also contains files with same names and

didn't change the code but it didn't work

Link to comment
Share on other sites

  • Developers

do you know what...

for these folders it worked fine, and for other folders it won't even match any file.

i've tried to change the folder names and it also contains files with same names and

didn't change the code but it didn't work

Well ... post an array that doesn't work and we will have a look. :D

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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