使用WinAPI类来查找文件

怎样用winapi查找文件本文传自:http://spaces.msn.com/AxGeek/ 
本例中使用到很多Axapta高级技巧,比如函数的嵌套等,值得大家揣摩。

例子中使用到的三个函数解释:

fileExists(_name)    若存在文件,则返回 true
   folderExists(_name)  若存在文件夹或文件,则返回true。
   pathExists(_name)    若存在文件夹,则返回true;

 

static void FindFile(Args _args)
{
    #File
    FileName fullFileName(FileName _path, FileName _fileName)
    {
        FileName    pathName;
        FileName    fileName;
        FileName    fileExtension;
        ;
        [pathName,fileName,fileExtension] = fileNameSplit(_fileName);
        return _path + '//' + fileName + fileExtension;
    }

    void findFiles(FileName _path,
    FileName _fileName,
    boolean _inclSubDir = true,
    FileName _prefix = fullFileName(_path,_fileName))
    {
        FileName    fileName;
        int         hdl;
        ;
        setprefix(_prefix);
        if (WinAPI::folderExists(_path))
        {
        [hdl,fileName] = WinApi::findFirstFile(fullFileName(_path,_fileName));
        while (fileName)
        {
            if (WinAPI::fileExists(fullFileName(_path,fileName)))
            info(fileName);
            fileName = WinApi::findNextFile(hdl);
        }
        WinApi::findClose(hdl);
        if (_inclSubDir)
        {
            [hdl, fileName] = WinAPI::findFirstFile(_path+'//'+#AllFiles);
            while (fileName)
            {
                if (strlwr(fileName) != strlwr(_fileName) &&
                strlwr(fileName) != strlwr('.')       &&
                strlwr(fileName) != strlwr('..')      &&
                WinAPI::pathExists(fullFileName(_path,fileName)))
                findFiles(fullFileName(_path,fileName), _fileName, _inclSubDir, fileName);
                fileName = WinApi::findNextFile(hdl);
            }
            WinApi::findClose(hdl);
        }
        }
    }
    findFiles('c://Program Files','*.doc');
}

原文地址:https://www.cnblogs.com/Fandyx/p/2761528.html