ScriptSpot

Forum topic · General Scripting

Recursive not inclduing files in root directory?

By dannyrs · 2019-11-18

Description

Hi,

I have lifted this portion of script from the maxscript reference to loop through all .max files in a root folder and all child folders. The script processes .max files in child folders but not .max files in the root folder... could someone help me figure it out please?

--fn getFilesRecursive root pattern =
(

dir_array = GetDirectories (root+"/*")
for d in dir_array do
join dir_array (GetDirectories (d+"/*"))
my_files = #()
for f in dir_array do
join my_files (getFiles (f + pattern))
my_files
)

location = getSavePath caption:"Files to process..."
--get all .max files from the specified folder --and all its subfolders:
getFilesRecursive location "*.max" -- change the folder here

Comments (1)

.

miauu · 2019-12-02

Try this:


(
	fn getFilesRecursive root pattern =
 	( 
		dir_array = GetDirectories (root+"/*")

		for d in dir_array do
		(
			join dir_array (GetDirectories (d+"/*"))
		)
		
		join dir_array (GetDirectories root)
		
		my_files = #()
		for f in dir_array do
		join my_files (getFiles (f + pattern))
		my_files
 	)
 
	location = getSavePath caption:"Files to process..."
	--get all .max files from the specified folder  --and all its subfolders:
	getFilesRecursive location "*.max"  -- change the folder here
)