Revolter Posted December 29, 2010 Share Posted December 29, 2010 (edited) this should make an array with all the mp3 files in the folder that contains the mp3 selected first but the array is empty. what is wrong? expandcollapse popup#include <Array.au3> #include <File.au3> #include <Sound.au3> Global $filearray[ 1 ][ 3 ] , $add Global $drive , $dir , $name , $ext Global $path , $pathdrive , $pathdir , $pathname , $pathext $add = FileOpenDialog( "Select the Mp3 file you want to play:" , @DesktopDir , "Mp3 Files (*.mp3)" , 3 ) If @error >= 1 Then Else $path = _PathSplit( $add , $pathdrive , $pathdir , $pathname , $pathext ) While $pathext <> ".mp3" If $pathext = "" Then ExitLoop MsgBox( 0 , "Mp3 Player" , "Not ''mp3'' file" ) $add = FileOpenDialog( "Select the Mp3 file you want to play:" , $address , "Mp3 Files (*.mp3)" , 3 ) $path = _PathSplit( $add , $pathdrive , $pathdir , $pathname , $pathext ) WEnd If $pathext <> "" Then $fname = $add EndIf EndIf _PathSplit( $fname , $drive , $dir , $name , $ext ) $filesearch = FileFindFirstFile( $drive & $dir & "*" & $ext ) While @error <> 1 $filenf = FileFindNextFile( $filesearch ) If @error Then ExitLoop _ArrayAdd( $filearray , $drive & $dir & $filenf ) $id3artist = _GetExtProp( $filearray[ UBound( $filearray ) - 1 ][ 1 ] , 13 ) $id3title = _GetExtProp( $filearray[ UBound( $filearray ) - 1 ][ 1 ] , 21 ) _PathSplit( $filearray[ UBound( $filearray ) - 1 ][ 1 ] , $drive , $dir , $name , $ext ) If $id3artist <> "" And $id3title <> "" Then $filearray[ UBound( $filearray ) - 1 ][ 2 ] = $id3artist & " - " & $id3title Else $filearray[ UBound( $filearray ) - 1 ][ 2 ] = $name EndIf WEnd FileClose( $filesearch ) _ArrayDisplay( $filearray ) Func _GetExtProp($sPath, $iProp) Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty $iExist = FileExists($sPath) If $iExist = 0 Then SetError(1) Return 0 Else $sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1))) $oShellApp = ObjCreate ("shell.application") $oDir = $oShellApp.NameSpace ($sDir) $oFile = $oDir.Parsename ($sFile) If $iProp = -1 Then Local $aProperty[35] For $i = 0 To 34 $aProperty[$i] = $oDir.GetDetailsOf ($oFile, $i) Next Return $aProperty Else $sProperty = $oDir.GetDetailsOf ($oFile, $iProp) If $sProperty = "" Then Return 0 Else Return $sProperty EndIf EndIf EndIf EndFunc Edited December 29, 2010 by Revolter [center]Sorry for my bad english. Trying my best :Dhttp://iulianonofrei.comhttp://www.last.fm/user/Revolt666 [/center] Link to comment Share on other sites More sharing options...
Developers Jos Posted December 29, 2010 Developers Share Posted December 29, 2010 Your ArrayAdd() udf looks wrongly coded. Check the helpfile for its proper syntax, but guess you need to create and maintain the array yourself since it multi dimensional. 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 More sharing options...
kylomas Posted December 29, 2010 Share Posted December 29, 2010 Revolter, $address in line 18 is undeclared, perhaps this is supposed to be $add?? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Revolter Posted December 29, 2010 Author Share Posted December 29, 2010 Revolter, $address in line 18 is undeclared, perhaps this is supposed to be $add??kylomasi extracted and modified a little this from a bigger script and forgot about it ... i'm working now to create it manually but i can't get it to work ... [center]Sorry for my bad english. Trying my best :Dhttp://iulianonofrei.comhttp://www.last.fm/user/Revolt666 [/center] Link to comment Share on other sites More sharing options...
kylomas Posted December 29, 2010 Share Posted December 29, 2010 Revolter, Two thing... It appears that you are trying to select a single MP3 file from a directory and then searching that directory for all other MP3 files. IS this correct? Secondly, as Jos said, _arrayadd is for 1 dimensional arrays, whereas you are trying to operate on a 2 dimensional array... kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Revolter Posted December 29, 2010 Author Share Posted December 29, 2010 Revolter, Two thing... It appears that you are trying to select a single MP3 file from a directory and then searching that directory for all other MP3 files. IS this correct? Secondly, as Jos said, _arrayadd is for 1 dimensional arrays, whereas you are trying to operate on a 2 dimensional array... kylomas first is correct and i understood the second thing, i said that i' m trying to build it manualy ... if you can tell me how to initialize it other way than : $filearray[1000000][3] or if is possible to increase it ... [center]Sorry for my bad english. Trying my best :Dhttp://iulianonofrei.comhttp://www.last.fm/user/Revolt666 [/center] Link to comment Share on other sites More sharing options...
kylomas Posted December 29, 2010 Share Posted December 29, 2010 Revolter, You can only redim the last dimension of an array (see doc)...it is easy enough to build a col/row list of these files but you may want to check out using a dictionary object for this... kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Revolter Posted December 29, 2010 Author Share Posted December 29, 2010 Revolter, You can only redim the last dimension of an array (see doc)...it is easy enough to build a col/row list of these files but you may want to check out using a dictionary object for this...kylomaswhat is a dictionary object? [center]Sorry for my bad english. Trying my best :Dhttp://iulianonofrei.comhttp://www.last.fm/user/Revolt666 [/center] Link to comment Share on other sites More sharing options...
UEZ Posted December 29, 2010 Share Posted December 29, 2010 Here my version: expandcollapse popup;coded by UEZ 2010 #include <Array.au3> Dim $ergebnis[1] $path = "c:\" If StringRight($path, 1) <> "\" Then $path &= "\" $depth = StringReplace($path, "\", "\") $depth = @extended - 1 If StringLeft($path, 2) = "\\" Then $depth -= 2 $file = ".mp3" ;to search for any file use "*" $ergebnis = File_Seeker($path, $file, $ergebnis, 1, 0, 1) ;searchs for files with extension .mp3 but dir names are excluded If Not @error Then _ArrayDisplay($ergebnis) Exit ;================================================================================================== ; Function Name: File_Seeker($path, $file, $array) ; Description: searchs for a file recursively on given drive ; Parameters: $path: path where to search ; $file: filename to search for ; $array: to save the search results ; Optional: ; $ext: search for file extension, e.g. .mp3 ; $exact: to search for exact file name (not case sensitive) ; $rec: to search recursively for files and folders ; $folder: include also folder names to search pattern ; $maxr: maximum of recursion depth, 0 = maxiumum ; Return Value(s): an array with the full path of the files, $array[0] = amount of found files ; Version: v0.85 Build 2010-12-01 Beta ; Author(s): UEZ ;================================================================================================== Func File_Seeker($path, $file, ByRef $aResults, $ext = 0, $exact = 0, $rec = 1, $folder = 0, $maxr = 0) Local $extended, $d If Not IsInt($maxr) Then Return SetError(2) If $file <> "" And IsArray($aResults) And BitAND($ext, $exact) <> 1 Then If StringLeft($path, 2) = "\\" Or (StringRegExp(StringLeft($path, 1), "(?i:[A-Z])") And StringMid($path, 2, 1) = ":") Then If $maxr Then $d = StringReplace($path, "\", "\") $d = @extended - 1 If StringLeft($path, 2) = "\\" Then $d -= 2 $d -= $depth ;~ ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $d = ' & $d & ">=" & $maxr & ": " & $path & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console If $d > $maxr Then Return SetError(5) EndIf If StringRight($path, 1) <> "\" Then $path &= "\" Local $seek, $suffix = "" Local $search = FileFindFirstFile($path & "*") If $search = -1 Then Return SetError(3) EndIf While 1 $seek = FileFindNextFile($search) $extended = @extended If @error Then ExitLoop If $extended And $rec Then File_Seeker($path & $seek & "\", $file, $aResults, $ext, $exact, $rec, $folder, $maxr) If $exact And Not $ext Then If $seek = $file Then _ArrayAdd($aResults, $path & $seek) Else If $ext Then If StringRegExp($seek, "(?i:\" & $file & "+$\b)") And StringLeft($file, 1) = "." Then If ($extended And $folder) Or Not $extended Then _ArrayAdd($aResults, $path & $seek) EndIf Else If $file = "*" Then If ($extended And $folder) Or Not $extended Then _ArrayAdd($aResults, $path & $seek) Else If StringInStr($file, ".") Then If StringRegExp($seek, "(?i:\" & $file & ")+") Then If ($extended And $folder) Or Not $extended Then _ArrayAdd($aResults, $path & $seek) EndIf Else If StringRegExp($seek, "(?i:" & $file & ")+") Then If ($extended And $folder) Or Not $extended Then _ArrayAdd($aResults, $path & $seek) EndIf EndIf EndIf EndIf EndIf WEnd FileClose($search) $aResults[0] = UBound($aResults) - 1 Return SetError(0, 0, $aResults) Else Return SetError(4) EndIf Else Return SetError(1) EndIf EndFunc Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Revolter Posted December 29, 2010 Author Share Posted December 29, 2010 Here my version:Br,UEZi finally got it without using your udf but thanks anyway [center]Sorry for my bad english. Trying my best :Dhttp://iulianonofrei.comhttp://www.last.fm/user/Revolt666 [/center] Link to comment Share on other sites More sharing options...
Tvern Posted December 29, 2010 Share Posted December 29, 2010 You can only redim the last dimension of an array (see doc)...it is easy enough to build a col/row list of these files but you may want to check out using a dictionary object for this... I might not understand this the way you intended it, but you can ReDim any dimension of an array while preserving it's contents, as long as you keep the number of dimensions the same. If the number of dimensions changes you can still ReDim, but the contents will be erased. Example: #include<array.au3> Local $aTest[1][2] For $i = 1 To 10 ReDim $aTest[$i][2] $aTest[$i-1][0] = $i & ",0" $aTest[$i-1][1] = $i & ",1" _ArrayDisplay($aTest) Next Be carefull of ReDim though. It can slow down script considerably when called often, but there are usually workarounds for this. Link to comment Share on other sites More sharing options...
kylomas Posted December 30, 2010 Share Posted December 30, 2010 Tvern, Revolter, My apologies, you are exactly correct as per the following:"The ReDim keyword is similar to Dim, except that ReDim preserves the values in the array instead of removing the values while resizing an array. The number of dimensions must remain the same, or the old array will be forgotten during the ReDim. The array will retain the scope (Global or Local) that it had prior to resizing."kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
JohnOne Posted December 30, 2010 Share Posted December 30, 2010 i finally got it without using your udf but thanks anyway I'd be interested to see how you accomplished it, any chance of sharing? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Revolter Posted December 30, 2010 Author Share Posted December 30, 2010 I'd be interested to see how you accomplished it, any chance of sharing? expandcollapse popup#include <Array.au3> #include <File.au3> #include <Sound.au3> Global $filearray[ 1000000 ][ 3 ] , $add , $i = 1 , $filearraysize Global $drive , $dir , $name , $ext Global $path , $pathdrive , $pathdir , $pathname , $pathext $add = FileOpenDialog( "Select the Mp3 file you want to play:" , @DesktopDir , "Mp3 Files (*.mp3)" , 3 ) If @error >= 1 Then Else $path = _PathSplit( $add , $pathdrive , $pathdir , $pathname , $pathext ) While $pathext <> ".mp3" If $pathext = "" Then ExitLoop MsgBox( 0 , "Mp3 Player" , "Not ''mp3'' file" ) $add = FileOpenDialog( "Select the Mp3 file you want to play:" , @DesktopDir , "Mp3 Files (*.mp3)" , 3 ) $path = _PathSplit( $add , $pathdrive , $pathdir , $pathname , $pathext ) WEnd If $pathext <> "" Then $fname = $add EndIf EndIf _PathSplit( $fname , $drive , $dir , $name , $ext ) $filesearch = FileFindFirstFile( $drive & $dir & "*" & $ext ) While @error <> 1 $filenf = FileFindNextFile( $filesearch ) If @error Then ExitLoop $filearray[ $i ][ 1 ] = _PathFull( $filenf ) $id3artist = _GetExtProp( $filearray[ $i ][ 1 ] , 20 ) $id3title = _GetExtProp( $filearray[ $i ][ 1 ] , 21 ) _PathSplit( $filearray[ $i ][ 1 ] , $drive , $dir , $name , $ext ) If $id3artist <> "" And $id3title <> "" Then $filearray[ $i ][ 2 ] = $id3artist & " - " & $id3title Else $filearray[ $i ][ 2 ] = $name EndIf $i = $i + 1 WEnd $filearraysize = $i FileClose( $filesearch ) For $i = 1 To $filearraysize ConsoleWrite( $filearray[ $i ][ 1 ] & @CRLF & " " & $filearray[ $i ][ 2 ] & @CRLF) Next Func _GetExtProp($sPath, $iProp) Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty $iExist = FileExists($sPath) If $iExist = 0 Then SetError(1) Return 0 Else $sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1))) $oShellApp = ObjCreate ("shell.application") $oDir = $oShellApp.NameSpace ($sDir) $oFile = $oDir.Parsename ($sFile) If $iProp = -1 Then Local $aProperty[35] For $i = 0 To 34 $aProperty[$i] = $oDir.GetDetailsOf ($oFile, $i) Next Return $aProperty Else $sProperty = $oDir.GetDetailsOf ($oFile, $iProp) If $sProperty = "" Then Return 0 Else Return $sProperty EndIf EndIf EndIf EndFunc [center]Sorry for my bad english. Trying my best :Dhttp://iulianonofrei.comhttp://www.last.fm/user/Revolt666 [/center] 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