September 28, 2020, 03:37:42 AM

Author Topic: mac load dir issue  (Read 134 times)

Offline wadmixfm

  • Jr. Member
  • **
  • Posts: 64
mac load dir issue
« on: August 23, 2020, 01:09:53 PM »
Code: [Select]
' loaddir.bmx
SuperStrict

' declare a string array
Local files:String[]
files = LoadDir("\Applications\Specdrum\Kits\Standard\")

For Local t:String = EachIn files
Print t
Next

** note **

the path you see is just a folder with my .wav sounds in there
i want to load them in to an array

for example

the files in the folder are like this

01) Bass Drum.wav
02) Snare.wav
03) Hi Tom.wav
04) Lo Tom.wav
05) Cowbell.wav
06) HHat CL.wav
07) HiHat Open.wav
08) Claps.wav
09) Rim Shot.wav
10) Guiro.wav

Building .loaddir
[ 97%] Processing:.loaddir.bmx
[ 98%] Compiling:.loaddir.bmx.gui.debug.macos.x64.c
[100%] Linking:.loaddir.debug

Executing:.loaddir.debug

01) Bass Drum.wav
06) HHat CL.wav
03) Hi Tom.wav
05) Cowbell.wav
02) Snare.wav
04) Lo Tom.wav
09) Rim Shot.wav
07) HiHat Open.wav
08) Claps.wav
10) Guiro.wav


Process complete

in windows the same code produces it in order but mac os catalina it produces the above

can someone help as its doing my head in :)

Lee

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1907
Re: mac load dir issue
« Reply #1 on: August 23, 2020, 01:42:01 PM »
The Mac and windows file systems are completely different. You can’t assume they are the same. If you need files in a certain order - then you will need to load them exactly, or sort them yourself

Offline GfK

  • Full Member
  • ***
  • Posts: 145
Re: mac load dir issue
« Reply #2 on: August 23, 2020, 02:12:42 PM »
Arrays probably aren't best suited for this implementation.  If it were me, I'd be looking at using a TMap with the filename as the Key (they have to be unique), and the file itself as the Value.

https://blitzmax.org/docs/en/api/brl/brl.map/
Intel I9-9900K 3.6-5.0GHz | GeForce RTX2070 8GB | 32GB RAM | 500GB NVMe M.2 SSD | 1TB HDD | Windows 10 x64.
MSI Apache Pro | I7-7700HQ | GeForce GTX1060 3GB | 8GB RAM | 128GB SSD | 1TB HDD | Windows 10 x64.

Offline wadmixfm

  • Jr. Member
  • **
  • Posts: 64
Re: mac load dir issue
« Reply #3 on: August 23, 2020, 02:54:04 PM »
so what is the mac looking at then when it sees the folder ???

is it looking at the size of the file , the date ,the length of the filename or when it was modified for example

i just can't work it out

i dont understand tmaps

the windows way was great you could look at a directory , load into an array like stands$[11]

then call them back in a loop

for example
Local namestd$[11]
Local folder$
Local jl
'get data from folder

' Define what folder To start with ...
folder$="\Applications\Specdrum\Kits\Standard"

Local myDir:Byte Ptr = ReadDir(folder$)

If myDir=0 Then RuntimeError folder+" does not exist!"
Global file:String=NextFile$(myDir)

While file
   If Lower(ExtractExt(file))="wav"
      namestd=namestd[..jl+1]
      namestd$[jl]=file$
      jl=jl+1
   EndIf
   file$=NextFile$(myDir)
Wend
CloseDir myDir


For Local i = 0 To 9

Print namestd$

Next

this works but its all jumbled

not in order

lee




Offline Derron

  • Hero Member
  • *****
  • Posts: 3180
Re: mac load dir issue
« Reply #4 on: August 23, 2020, 03:15:39 PM »
Loaddir...returns an array of strings.

ThisArray = ThisArray.sort(true)
Will sort it for you

Bye
Ron

Offline wadmixfm

  • Jr. Member
  • **
  • Posts: 64
Re: mac load dir issue
« Reply #5 on: August 23, 2020, 05:08:03 PM »
cheers sorted

Code: [Select]
Import Brl.StandardIO
Local namestd$[11]
Local folder$
Local jl

Local list:TList = CreateList()

' add some string objects to the begin of the list

'get data from folder

' Define what folder To start with ...
folder$="\Applications\Specdrum\Kits\Standard"

Local myDir:Byte Ptr = ReadDir(folder$)

If myDir=0 Then RuntimeError folder+" does not exist!"
Global file:String=NextFile$(myDir)

While file
If Lower(ExtractExt(file))="wav"

namestd=namestd[..jl+1]
namestd$[jl]=file$
ListAddLast(list, namestd$[jl])
jl=jl+1
EndIf
file$=NextFile$(myDir)
Wend
CloseDir myDir

SortList(list, True)

' enumerate all the strings in the list
For Local a:String = EachIn list
Print a
Next


this prints out

Building untitled2
[ 97%] Processing:untitled2.bmx
[ 98%] Compiling:untitled2.bmx.gui.debug.macos.x64.c
[100%] Linking:untitled2.debug
Executing:untitled2.debug

01) Bass Drum.wav
02) Snare.wav
03) Hi Tom.wav
04) Lo Tom.wav
05) Cowbell.wav
06) HHat CL.wav
07) HiHat Open.wav
08) Claps.wav
09) Rim Shot.wav
10) Guiro.wav

Process complete

thanks for the help peeps

lee

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal