Sign in to follow this  
Followers 0
LinuZ

A playlist problem!

14 posts in this topic

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)

EndFunc

Just 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!

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Example:

#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 by rasim

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Example:

#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 by LinuZ

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by LinuZ

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hmmm...i edited my first post in this topic. Try again.

Edited by rasim

Share this post


Link to post
Share on other sites

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
Hi,

You just mean

StringReplace ( $add, "|", @CRLF)oÝ÷ Øaw¥±éÉ·ºÚ"µÍÝ[ÔYÑ^XÙH
    ÌÍØY ][ÝÉÌLß ][ÝËÔ
randall

Share this post


Link to post
Share on other sites

#8 ·  Posted (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:

#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 by LinuZ

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by LinuZ

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by weaponx

Share this post


Link to post
Share on other sites

#12 ·  Posted (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 by LinuZ

Share this post


Link to post
Share on other sites

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  ÌÍÜÝ[Ê

Share this post


Link to post
Share on other sites

Sorry ;):)

And thanks again! You are very skilled!

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  
Followers 0