AutoMT Posted July 3, 2008 Share Posted July 3, 2008 Okay, I have a folder with the following files in it:testaudio.mp3testaudio02.mp3testaudio02.mp3wrectestaudio03.mp3testaudio03.mp3wrecAs 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. Link to comment Share on other sites More sharing options...
Airwolf Posted July 3, 2008 Share Posted July 3, 2008 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 Link to comment Share on other sites More sharing options...
Paulie Posted July 3, 2008 Share Posted July 3, 2008 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 Link to comment Share on other sites More sharing options...
PartyPooper Posted July 3, 2008 Share Posted July 3, 2008 (edited) 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]) Next 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 July 3, 2008 by PartyPooper Link to comment Share on other sites More sharing options...
AutoMT Posted July 4, 2008 Author Share Posted July 4, 2008 (edited) 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) EndFunc Func StartFunc($Function) ConsoleWrite(">" & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & " " & @UserName & " " & @ComputerName & ": " & $Function & @CRLF) EndFunc Func CountWrecs() StartFunc("CountWrecs()") $CountWrec = FileFindFirstFile($AudioDir & "*.mp3wrec") If $CountWrec = -1 Then LogIt("No mp3wrecs found") ; go to next function Else $WrecArray = _ArrayCreate($WrecArray) While 1 $Wrec = FileFindNextFile($CountWrec) If @error Then ExitLoop $WrecCountTotal = $WrecCountTotal + 1 _ArrayAdd($WrecArray, $Wrec) LogIt($Wrec & " added to $WrecArray") WEnd LogIt("Total mp3wrecs found: " & $WrecCountTotal) _ArrayDisplay($WrecArray) FileClose($CountWrec) FileClose($Wrec) ;$CountWrecsDone = 1 SearchWrecArray() EndIf EndFunc 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 July 4, 2008 by AutoMT 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