Used in the project, find all msml files in a folder, use string to return their absolute paths, and put them in a list. There may be folders in the folder, and msml files may be placed in any level-1 folder. Here we actually write a basic recursive folder to find a method that meets the requirements.
Package meta. util; import Java. io. file; import Java. util. arraylist; public class scandir {private arraylist <string> filelist = new arraylist <string> (); // put it in a list public arraylist <string> getfilelist () {return filelist ;} public void setfilelist (arraylist <string> filelist) {This. filelist = filelist;} // recursively searches for all msml files under the strpath with the public void refreshfilelist (string strpath) {string filename; // file name string SUF ;/ /File suffix file dir = new file (strpath); // folder dirfile [] files = dir. listfiles (); // all files in the folder or folders if (Files = NULL) return; For (INT I = 0; I <files. length; I ++) {If (files [I]. isdirectory () {system. out. println ("---" + files [I]. getabsolutepath (); refreshfilelist (files [I]. getabsolutepath (); // recursive folder !!!} Else {filename = files [I]. getname (); Int J = filename. lastindexof (". "); SUF = filename. substring (J + 1); // obtain the file suffix if (SUF. equalsignorecase ("msml") // determine whether the file is a msml suffix {string strfilename = files [I]. getabsolutepath (). tolowercase (); filelist. add (files [I]. getabsolutepath (); // Add the path of the file to filelist before the file is created }}}}}
After such a list is obtained, each msml file can be parsed in sequence, and Dom or sax can be used to obtain metadata information.