Jump to content
Sign in to follow this  

Separating items within an array

Recommended Posts


Okay, I have a folder with the following files in it:






As you can see a couple of them have the "mp3wrec" file extension. I've used _FileListToArray to add all those files to an array called $mp3List. What I'm wanting to do is sort the mp3wrec files from the regular mp3s (my script only wants to deal with the regular mp3s). The only way I'd know how to do this is to do a StringSplit on each index in the array, using the "." as the delimiter, thus creating another array and a whole lot more work. But can anybody see an easier way to separate the mp3s from the mp3wrecs? I'm having some trouble using StringSplit within an array. And usually when I'm having trouble with something it's because what I'm trying to do can usually be done in about two lines of code instead of a whole function. :)

Share this post

Link to post
Share on other sites

Build a query in StringRegExp() to only find files that end in ".mp3". A simpler method would be to StringRight($string,4) and only do something if the result is ".mp3". A StringRight($string,4) on a .mp3wrec file would return "wrec".

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post

Link to post
Share on other sites

If StringRight($String, 4) = "wrec" then; compares last 4 digits to "wreck"

Or maybe

if not StringInStr(StringRight($String,4),".") then;checks for "." in the last 4 characters of filename

Share this post

Link to post
Share on other sites

How about using FileListToArray first to sort out the .mp3's from the .mp3wrec's?

Something like:

$a_UserFileList = _FileListToArray($s_Directory, "*.mp3", 1)

then reading each file into an array using _FileListToArray like:

For $x = 1 to UserFileList[0]

_FileReadToArray($s_Directory & $a_UserFileList[$x], $a_UserFile[$x])


Don't forget to put a "\" at the end of the $s_Directory variable.

Once you've done your business with the .mp3's, you can do the same for the .mp3wrec's.

Edit: Fixed typo

Edited by PartyPooper

Share this post

Link to post
Share on other sites

I've been doing some mucking around of my own and came out with something similar to what PartyPooper suggested. Except I've used FileFindFirstFile to add the mp3wrecs to an array one by one. This adds "testaudio01.mp3wrec" and "testaudio02.mp3wrec" to an array:

Func LogIt($LogText)
    ConsoleWrite(@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & " " & @UserName & " " & @ComputerName & ": " & $LogText & @CRLF)

Func StartFunc($Function)
    ConsoleWrite(">" & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & " " & @UserName & " " & @ComputerName & ": " & $Function & @CRLF)

Func CountWrecs()
    $CountWrec = FileFindFirstFile($AudioDir & "*.mp3wrec")
    If $CountWrec = -1 Then
        LogIt("No mp3wrecs found")
        ; go to next function
        $WrecArray = _ArrayCreate($WrecArray)
        While 1
            $Wrec = FileFindNextFile($CountWrec)
            If @error Then ExitLoop
            $WrecCountTotal = $WrecCountTotal + 1
            _ArrayAdd($WrecArray, $Wrec)
            LogIt($Wrec & " added to $WrecArray")
        LogIt("Total mp3wrecs found: " & $WrecCountTotal)
        ;$CountWrecsDone = 1

For example, I am trying to search each item in the array to see if it contains the string $MP3Name[1], which in this case is "testaudio01". However it's not finding it, even though there actually is an item in the array named "testaudio01.mp3wrec". My little LogIt function says this:

04/07/2008 11:14 taylorsu JD37394: Searching testaudio01.mp3wrec for string testaudio01

04/07/2008 11:14 taylorsu JD37394: String testaudio01 not found in testaudio01.mp3wrec

04/07/2008 11:14 taylorsu JD37394: Searching testaudio02.mp3wrec for string testaudio01

04/07/2008 11:14 taylorsu JD37394: String testaudio01 not found in testaudio02.mp3wrec

I'm not sure whether it's a problem with my StringInStr or the For $i =. This is the first time I've used a For $i =, am I doing it the right way?

EDIT: Holy crap I had the parameters in StringInStr around the wrong way. Incredible. And I've done TONS of StringInStr's in the past too. Well, I'm an idiot.

Edited by AutoMT

Share this post

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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.