LinuZ Posted March 9, 2008 Share Posted March 9, 2008 So here is the code:#include <File.au3> $ini = "options.ini" $curpl = "current.lst" If FileExists($ini) = False Then _FileCreate ($ini) IniWriteSection($ini, "Playlist", "Current=" & $curpl & @LF & "Last=") IniWriteSection($ini, "Auto-Update", "Enabled=1") IniWriteSection($ini, "Minimize2Tray", "Enabled=1") EndIf If FileExists($curpl) = False Then _FileCreate($curpl) _Addfolder() Func _Addfolder() $string = "" Dim $songs[2000] $old = IniRead($ini, "Playlist", "Last", "") $folder = FileSelectFolder ("Choose the music folder", "", 0, $old) IniWrite($ini, "Playlist", "Last", $folder) $songs = _FileListToArray ($folder, "*.*", 1) FOR $1 IN $songs If IsNumber($1) = False Then $string = $string & $folder & "\" & $1 & @CRLF EndIf NEXT FileWrite($curpl, $string) EndFuncJust a simple add folder function of soon an audio player. So my question is: How can I get it to list the files in the subfolders too? (I have tried, I sat a long time yesterday but nothing worked)This is a mathematical/loop problem!Thanks in advance! And comments about it anyways are welcome! Link to comment Share on other sites More sharing options...
randallc Posted March 9, 2008 Share Posted March 9, 2008 Hi, Try _FileListToArray3 in link from signature. Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
rasim Posted March 9, 2008 Share Posted March 9, 2008 (edited) Example: expandcollapse popup#include <File.au3> Dim $ini = @ScriptDir & "\options.ini" Dim $curpl = @ScriptDir & "\current.lst" IniWriteSection($ini, "Playlist", "Current=" & $curpl) IniWriteSection($ini, "Auto-Update", "Enabled=1") IniWriteSection($ini, "Minimize2Tray", "Enabled=1") $old = IniRead($ini, "Playlist", "Last", "") $folder = FileSelectFolder("Choose the music folder", "", 0, $old) If @error Then Exit IniWrite($ini, "Playlist", "Last", $folder) Dim $OpenFile = FileOpen(@ScriptDir & "\current.lst", 2) _Addfolder($folder) FileClose($OpenFile) Func _Addfolder($sPath) Local $iFolder, $iFullPath, $sRet $iFolder = _FileListToArray($sPath, "*.*", 0) If @error Then Return For $i = 1 To $iFolder[0] $iFullPath = $sPath & "\" & $iFolder[$i] If StringInStr(FileGetAttrib($iFullPath), "D") Then _Addfolder($iFullPath) Else FileWriteLine($OpenFile, $iFullPath) EndIf Next EndFunc Edited March 9, 2008 by rasim Link to comment Share on other sites More sharing options...
LinuZ Posted March 9, 2008 Author Share Posted March 9, 2008 (edited) Example: expandcollapse popup#include <File.au3> Dim $ini = @ScriptDir & "\options.ini" Dim $curpl = @ScriptDir & "\current.lst" IniWriteSection($ini, "Playlist", "Current=" & $curpl) IniWriteSection($ini, "Auto-Update", "Enabled=1") IniWriteSection($ini, "Minimize2Tray", "Enabled=1") $old = IniRead($ini, "Playlist", "Last", "") $folder = FileSelectFolder("Choose the music folder", "", 0, $old) If @error Then Exit IniWrite($ini, "Playlist", "Last", $folder) Dim $OpenFile = FileOpen(@ScriptDir & "\current.lst", 2) _Addfolder($folder) FileClose($OpenFile) Func _Addfolder($sPath) Local $iFolder, $iFullPath, $sRet $iFolder = _FileListToArray($folder, "*.*") If @error Then Return For $i = 1 To $iFolder[0] $iFullPath = $sPath & "\" & $iFolder[$i] If StringInStr(FileGetAttrib($iFullPath), "D") Then $sRet = _Addfolder($iFullPath) Else FileWriteLine($OpenFile, $iFullPath) EndIf Next EndFunc This makes the list of files say that all files are in every subfolder. Like I have 5 songs in 2 folders: C:\Music\folder1\1.mp3 C:\Music\folder1\2.mp3 C:\Music\folder1\3.mp3 C:\Music\folder2\4.mp3 C:\Music\folder2\5.mp3 And the list from your script would say: C:\Music\folder1\1.mp3 C:\Music\folder1\2.mp3 C:\Music\folder1\3.mp3 C:\Music\folder1\4.mp3 C:\Music\folder1\5.mp3 C:\Music\folder2\1.mp3 C:\Music\folder2\2.mp3 C:\Music\folder2\3.mp3 C:\Music\folder2\4.mp3 C:\Music\folder2\5.mp3 @Randall, Ill check it out! Edited March 9, 2008 by LinuZ Link to comment Share on other sites More sharing options...
LinuZ Posted March 9, 2008 Author Share Posted March 9, 2008 (edited) Works like a charm, randal! It even fixed my problem with many filetypes! Thanks very much! EDIT: Next problem, LolZ_! What is the problem with this function? Ive tried much! Func Addsingle() $curpl = "playlist.lst" $add = FileOpenDialog("Add song to playlist", "", $filedialog, 4, $olds) ConsoleWrite($add) StringRegExpReplace ( $add, "|", @CRLF) ConsoleWrite($add) FileWrite($curpl, $add) EndFunc Edited March 9, 2008 by LinuZ Link to comment Share on other sites More sharing options...
rasim Posted March 9, 2008 Share Posted March 9, 2008 (edited) Hmmm...i edited my first post in this topic. Try again. Edited March 9, 2008 by rasim Link to comment Share on other sites More sharing options...
randallc Posted March 9, 2008 Share Posted March 9, 2008 Works like a charm, randal! It even fixed my problem with many filetypes! Thanks very much! EDIT: Next problem, LolZ_! What is the problem with this function? Ive tried much! Func Addsingle() $curpl = "playlist.lst" $add = FileOpenDialog("Add song to playlist", "", $filedialog, 4, $olds) ConsoleWrite($add) StringRegExpReplace ( $add, "|", @CRLF) ConsoleWrite($add) FileWrite($curpl, $add) EndFuncHi, You just mean StringReplace ( $add, "|", @CRLF)oÝ÷ Øaw¥±éÉ·ºÚ"µÍÝ[ÔYÑ^XÙH ÌÍØY ][ÝÉÌLß ][ÝËÔrandall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
LinuZ Posted March 9, 2008 Author Share Posted March 9, 2008 (edited) I tried it but it didnt help as you know the script is supposed to write the chosen songs to a playlist, I give the whole source so it is easier: expandcollapse popup#include <File.au3> #include "FileListToArray3.au3" Dim $ini = "options.ini" Dim $curpl = "current.lst" $filetypes = "*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aiff;*.xm;*.it;*.s3m;*.mod;*.mtm;*.umx;*.mo3" $filedialog = "All supported (*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aiff;*.xm;*.it;*.s3m;*.mod;*.mtm;*.umx;*.mo3) |Stream (*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aiff)|Chip-tunes (*.xm;*.it;*.s3m;*.mod;*.mtm;*.umx)|MO3 music (*.mo3)" If FileExists($ini) = False Then _FileCreate ($ini) IniWriteSection($ini, "Playlist", "Current=" & $curpl & @LF & "Lastfolder=" & @LF & "Lastsong=") IniWriteSection($ini, "Auto-Update", "Enabled=1") IniWriteSection($ini, "Minimize2Tray", "Enabled=1") EndIf If FileExists($curpl) = False Then _FileCreate($curpl) Addsingle() Func Addfolder();;Works great! $string = "" Dim $songs[2000] $oldf = IniRead($ini, "Playlist", "Lastfolder", "") $folder = FileSelectFolder ("Choose the music folder", "", 0, $oldf) IniWrite($ini, "Playlist", "Lastfolder", $folder) $songs = _FileListToArray3($folder, $filetypes, 1, 1, 0, "", 1) If @error = 0 Then For $1 = 1 To $songs[0] $string = $string & $folder & "\" & $songs[$1] & @CRLF Next Else MsgBox(0, "", "No files selected") EndIf ;;$open = FileOpen($curpl, 1) FileWrite($curpl, $string) ;;FileClose($open) EndFunc Func Addsingle();;Doesnt work, really $olds = IniRead($ini, "Playlist", "Lastsong", "") $add = FileOpenDialog("Add song to playlist", "", $filedialog, 4, $olds) IniWrite($ini, "Playlist", "Lastsong", $add) ConsoleWrite($add) StringRegExpReplace ( $add, "\|", @CRLF) ConsoleWrite($add) FileWrite($curpl, $add) EndFunc Func SavePlaylist() $save = FileSaveDialog ( "Save playlist", "", "LAP playlist (*.lst)", 2) FileCopy($curpl, $save) EndFunc My problem is the "Addsingle" function that is supposed to be able to add 1 or more files to the playlist.lst, it gets the songs but doesnt add them to the playlist! Why? Thanks for helping! Edited March 9, 2008 by LinuZ Link to comment Share on other sites More sharing options...
weaponx Posted March 11, 2008 Share Posted March 11, 2008 String functions must be assigned for their result to be saved. StringRegExpReplace ( $add, "\|", @CRLF) Needs to be: $add = StringRegExpReplace ( $add, "\|", @CRLF) If you don't do this, $add is never actually changed. Link to comment Share on other sites More sharing options...
LinuZ Posted March 11, 2008 Author Share Posted March 11, 2008 (edited) Thanks, it helped, but what is wrong with this code? #include <File.au3> $filedialog = "All supported (*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aiff;*.xm;*.it;*.s3m;*.mod;*.mtm;*.umx;*.mo3)" $add = FileOpenDialog("Add song to playlist", "", $filedialog, 4) $add2 = StringRegExpReplace ( $add, "\|", @CRLF) MsgBox(0, "", $add2) $test = _FileCreate ("C:\test.txt") FileOpen($test, 1) FileWrite($test, $add2) The file I get as outcome is completely blank... Woot? Edited March 11, 2008 by LinuZ Link to comment Share on other sites More sharing options...
weaponx Posted March 11, 2008 Share Posted March 11, 2008 (edited) _FileCreate() doesn't return a handle, which is required by FileWrite in this case. $test = _FileCreate ("C:\test.txt") $fileHandle = FileOpen("C:\test.txt", 1) FileWrite($fileHandle, $add2) You don't need _FileCreate, FileOpen should create the file if it doesn't exist. Edited March 11, 2008 by weaponx Link to comment Share on other sites More sharing options...
LinuZ Posted March 11, 2008 Author Share Posted March 11, 2008 (edited) Thanks! It worked nicely! I am sorry to bug you but this should do nearly the same thing and I cant get it to work :/ $filedialog = "All supported (*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aiff;*.xm;*.it;*.s3m;*.mod;*.mtm;*.umx;*.mo3)" $string = "" $add = FileOpenDialog("Add song to playlist", "", $filedialog, 4) $add = StringRegExpReplace ( $add, "|", @CRLF) $add = StringSplit($add, "|") For $1 = 1 To $add[1] $string = $string & $add[1] & "\" & $add[$1] & @CRLF Next $fileHandle = FileOpen("C:\test.txt", 1) FileWrite($fileHandle, $add) The difference is that it writes whole path... Edited March 11, 2008 by LinuZ Link to comment Share on other sites More sharing options...
weaponx Posted March 11, 2008 Share Posted March 11, 2008 Thanks! It worked nicely! I am sorry to bug you but this should do nearly the same thing and I cant get it to work :/ $filedialog = "All supported (*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aiff;*.xm;*.it;*.s3m;*.mod;*.mtm;*.umx;*.mo3)" $string = "" $add = FileOpenDialog("Add song to playlist", "", $filedialog, 4) $add = StringRegExpReplace ( $add, "|", @CRLF) $add = StringSplit($add, "|") For $1 = 1 To $add[1] $string = $string & $add[1] & "\" & $add[$1] & @CRLF Next $fileHandle = FileOpen("C:\test.txt", 1) FileWrite($fileHandle, $add)oÝ÷ Ûú®¢×¢·!®+-±©v÷öÛ¬z{¦mêì{Ú®&éÚëºÚ"µÍ ÌÍÙ[YX[ÙÈH ][ÝÐ[ÝÜY ÎÊÊNÊÙÙÎÊØ]ÊZYÊNÊ]ÊÌÛNÊ[ÙÊ]NÊ[^Ê[ÌÊI][Ý ÌÍÜÝ[ÈH ][ÝÉ][Ý ÌÍØYH[SÜ[X[ÙÊ ][ÝÐYÛÛÈÈ^[Ý ][ÝË ][ÝÉ][ÝË ÌÍÙ[YX[ÙË B ÌÍØYHÝ[ÔYÑ^XÙH ÌÍØY ][Ýß ][ÝËÔB ÌÍØYHÝ[ÔÜ] ÌÍØY ][Ýß ][ÝÊBÜ ÌÍÖHHÈ ÌÍØYÌBBIÌÍÜÝ[È [ÏH ÌÍØYÉÌÍÖH [ÈÔ^ ÌÍÙ[R[HH[SÜ[ ][ÝÐÎÌLÝÝ ][ÝËJB[UÜ]J ÌÍÙ[R[K ÌÍÜÝ[Ê Link to comment Share on other sites More sharing options...
LinuZ Posted March 11, 2008 Author Share Posted March 11, 2008 Sorry And thanks again! You are very skilled! 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