Mel Script - Listing Directory Contents




One of the biggest problems when working on large scale projects is that over time the amount of files you have increases exponentially. Often some of the most useful scripts are those which in some way manage files for you and your project.

Often scripts that say, render all maya binary files within a given directory, or check that all textures in the scene are in the correct diirectory (ie, batch processing scripts) are normally the scripts that save your sanity at the end of a project!

Therefore, knowing how to get lists of the files on the hard drive is important!





Example 1 : Listing the users workspace

getFileList have two possible flags, the first is -folder which is used to specify the directory to list. The second flag is -filespec. The -filespec flag is used to specify a wildcard, the following example just lists all mel files within the user scripts directory.

getFileList -folder `internalVar -userScriptDir` -filespec "*.mel";



		// get a path to the users current workspace directory
		$path = `internalVar -userWorkspaceDir`;
		// get a list of all files in that directory
		string $files[] = `getFileList -folder $path`;
		// loop through each file and print
		for( $file in $files ) {
			// action to repeat
			print( "file= " + $file + "\n" );