本例中使用到很多Axapta高级技巧,比如函数的嵌套等,值得大家揣摩。
例子中使用到的三个函数解释:
fileExists(_name) 若存在文件,则返回 true。
folderExists(_name) 若存在文件夹或文件,则返回true。
pathExists(_name) 若存在文件夹,则返回true。
1 static void FindFile(Args _args) 2 { 3 #File 4 FileName fullFileName(FileName _path, FileName _fileName) 5 { 6 FileName pathName; 7 FileName fileName; 8 FileName fileExtension; 9 ; 10 [pathName,fileName,fileExtension] = fileNameSplit(_fileName); 11 return _path + '\\' + fileName + fileExtension; 12 } 13 14 void findFiles(FileName _path, 15 FileName _fileName, 16 boolean _inclSubDir = true, 17 FileName _prefix = fullFileName(_path,_fileName)) 18 { 19 FileName fileName; 20 int hdl; 21 ; 22 setprefix(_prefix); 23 if (WinAPI::folderExists(_path)) 24 { 25 [hdl,fileName] = WinApi::findFirstFile(fullFileName(_path,_fileName)); 26 while (fileName) 27 { 28 if (WinAPI::fileExists(fullFileName(_path,fileName))) 29 info(fileName); 30 fileName = WinApi::findNextFile(hdl); 31 } 32 WinApi::findClose(hdl); 33 if (_inclSubDir) 34 { 35 [hdl, fileName] = WinAPI::findFirstFile(_path+'\\'+#AllFiles); 36 while (fileName) 37 { 38 if (strlwr(fileName) != strlwr(_fileName) && 39 strlwr(fileName) != strlwr('.') && 40 strlwr(fileName) != strlwr('..') && 41 WinAPI::pathExists(fullFileName(_path,fileName))) 42 findFiles(fullFileName(_path,fileName), _fileName, _inclSubDir, fileName); 43 fileName = WinApi::findNextFile(hdl); 44 } 45 WinApi::findClose(hdl); 46 } 47 } 48 } 49 findFiles('c:\\Program Files','*.doc'); 50 }