Task

Walk a given directory tree and print files matching a given pattern.


Note: This task is for recursive methods.   These tasks should read an entire directory tree, not a single directory.


Note: Please be careful when running any code examples found here.



Related task

   Walk a directory/Non-recursively   (read a single directory). 


import Nanoquery.IO
 
def get_files(dirname)
	local_filenames = new(File).listDir(dirname)
 
	filenames = {}
 
	for i in range(0, len(local_filenames) - 1)
		if len(local_filenames) > 0
			if not new(File, local_filenames[i]).isDir()
				filenames.append(local_filenames[i])
			else
				filenames += get_files(local_filenames[i])
			end
		end
	end
 
	return filenames
end
 
f = new(File)
for file in get_files("/")
	if lower(f.getExtension(file)) = ".mp3"
		println file
	end
end