I want to extract the file names in this structure recursively. -

Code:
var DirectoryTree = {
    dir: 'project1',
    files: [
        'proj.config', {
            dir: 'src',
            files: [
                'name.htm',
                'dept.htm',
                'salary.htm', {
                    dir: 'scripts',
                    files: [
                        'name.js',
                        'dept.js',
                        'salary.js'
                    ]
                }
            ]
        }, {
            dir: 'project2',
            files: [
                        'f1.htm',
                        'f2.htm',
                        'f3.htm'
                    ]
           }
    ]
};
I wrote the following code and got all the file names. But now I also want to extract the file names that are under a subfolder i.e src. I pass the subfolder name as the second argument. Here is the code now -

Code:
fileNames : function(fileSystem, subFolder){
		var result = [];
		
		(function findFiles(fileSystem){
			var files = fileSystem.files;
			
			if(typeof files !== 'undefined'){
				for(var i=0; i<files.length; i++){
					if(typeof files[i] === 'string') {
						result.push(files[i]);
					}else{
						findFiles(files[i]);
					}
				}
			}
		})(fileSystem);
	
		return result;
	}
The code now returns all the file names in the directory structure. I want to modify this to support both functionality. It should return all the file names in the structure and when there is a value passed into the subfolder it gives all the files beneath it. So in this case when i pass "SRC" as my subfolder it should return 5 files 'name.htm', 'dept.htm', 'salary.htm', 'name.htm', 'dept.htm', 'salary.htm'.

How can i do this?