Notifications
Clear all

[Closed] problem with nested array

Hi,

I have a problem with a nested array. The array nests items via function, maybe this is the cause?

recentFiles = #(
	"I:\PROJECTS\Module04\assets\FX\DesertDustFX\Module04_assets_FX_DesertDustFX_DesertDustFX_V01_v002.max", 
	"I:\PROJECTS\Module04\seq\seq01\shot0010	ake0010\Camera\Module04_seq_seq01_shot0010_take0010_Camera_Camera_V01_v005.max"
)

fn splitRecent _ARRAY = (		-- given an _ARRAY, it splits them in two, eight item 1) file names and 2) file paths
	eightItems = #()
	pathsArr = #()
	filesArr = #()
	
	x = 8
	if  (_ARRAY.count <= 8) do (
		x = _ARRAY.count
	)
	i = _ARRAY.count
	while i > (_ARRAY.count - x) do (
		append eightItems _ARRAY[i]
		i -= 1
		if i==0 do exit
	)
	
	for obj in eightItems do (
		paths = ""
		tmp = filterstring obj "\\"
		for j=1 to (tmp.count - 1) do (
			paths += tmp[j] + "\\"
		)
		append filesArr tmp[tmp.count]
		append pathsArr paths
	)
	append eightItems filesArr
	append eightItems pathsArr
	eightItems
)

testArr = #()
 
testArr = splitRecent recentFiles 

for obj in testArr do (
	format "Item:		%
" obj
)

When I make the function to return unnested arrays it’s okey. But when I want to return nested it’s bugged

Maybe a function cannot return a nested array?

3 Replies

would be better to make the function works right and simple first.
as i understand you have an original array of filepaths and you want to split paths into two array where one contains path parts and second contains filename parts.

ok. do it easy:

fn splitFilepaths paths =
(
    filepaths = #()
    filenames = #()
    for file in files do
    (
        append filepaths (getfilenamepath file)
        append filenames (filenamefrompath file)
    )
    #(filepaths, filenames)
)

after that you can debug why anything works wrong

ok I didn’t know we have functions for splitting paths and names. Thats awsome and really makes the thing super easy and clear Even both functions work the same the simpler one works fine, no bugs! thx again:)

but i suggest to use structures in your case. where you can keep an original path and both split path parts:

struct PathInfo (fullpath, path, file)
pathinfos = for file in files collect
(
    path = getfilenamepath file
    file = filenamefrompath file
    PathInfo fullpath:file path:path file:file
)