Main Menu

ReadDir

Started by stratum, October 02, 2005, 06:44:44 AM

Previous topic - Next topic

stratum

Hello,

I have a problem with the working of ReadDir. The examples in the manual are not working. I want to read a directory with background music and have the file names (with path). This way the user can choose their own music with in the program.

The code I use to read the directory is this

Function loadMusic()
MusicDir$ = CurrentDir$() + "Music\"
  ReadDir MusicDir$, "" , 0 , 1
  musicCounter = 1
  For Files = 0 To GetDirSize()-1
    titles$(musicCounter) = GetDirFile$(files)
    Inc musicCounter
    If musicCounter > 30 Then Exitfunction
 Next
EndFunction


The path MusicDir$ is correct and their are 13 music files in that dir, but the GetDirFiles$() returns 0, which means, according the manual, that the internal list (array) is empty.

What am I doing wrong?

Regards

Theo

kevin

Yeah, there's prolly something going on with GetdirFile$().   You can use GetDir$().  Although Readdir will store folders/filename etc separately. So you should check of type of entry your peek from the dir list

A bit like this.


Dim titles$(1)
loadmusic2()

For lp=1 to getArrayElements(titles$(),1)
print titles$(lp)
next  
Sync
waitkey

Function loadMusic2()
; MusicDir$ = CurrentDir$() + "Music\"
 musicdir$="c:\"

 ReadDir MusicDir$, "" , 0 , 0
 musicCounter = 1
 For Files = 0 To GetDirSize()-1
 
  ; Check if this entry is a file ?
  if GetDirFileType(Files)=1
    ; Check if this index within bounds of the dest array size
     if MusicCounter> GetArrayElements(Titles$(),1)
  redim Titles$(GetArrayElements(Titles$(),1)*2)
 endif
  ; Store the filename
    Titles$(musicCounter) = GetDirFile$(files)
    Inc musicCounter
endif
 Next
EndFunction





 Note:  LoadMusic is reserved word in PB1.089

stratum

Thanks Kevin,

With some adjustments I got it working and my program can handles the user choice of background music.

Cheers

Theo :D