win编程笔记---文件之类

万恶的win编程

计算机模型里,应用编程面向系统。在win编程的时候就有系统资源这么个东西,具体是win核心编程之类书里的。

资源的申请,释放,同步,权限,安全,很麻烦。

问题:文件删除失败,被程序占用。问题很简单,属于人sb了

代码:

void FileMonitor::FileSearch(const TCHAR *szRootPath)
{
    using std::wstring;
    WIN32_FIND_DATA FindFileData;
    WIN32_FIND_DATA FileData;
    HANDLE hFind;
    wstring NodePath;
    wstring rootPath;
    bool  Ret = true;
    TCHAR tmp[1024] = { 0 };
    m_pNotifyObj->debugLog(szRootPath);
    NodePath.assign(szRootPath);
    rootPath = szRootPath;
    rootPath += _T("\\*.*");
    //FindFileData.dwFileAttributes
    hFind = FindFirstFile(rootPath.c_str(), &FindFileData);
    while ((hFind != INVALID_HANDLE_VALUE) && (Ret))
    {
        m_pNotifyObj->debugLog(_T("FileSearch"));
        if (IS_SON_PATH(FindFileData))
        {
            //组报文;
            NodePath += _T("\\");
            NodePath += FindFileData.cFileName;
            //NodePath += _T("\\*");
            _tcscpy(tmp,NodePath.c_str());
            m_pNotifyObj->debugLog(_T("sun path"));
            m_pNotifyObj->debugLog(tmp);
            FileSearch(tmp);
        }
        else if (IS_DAD_PATH(FindFileData))
        {
            m_pNotifyObj->debugLog(_T("dad path"));
        }
        else
        {
            //如果是WMV,查找其签名---校验
            //TODO 校验函数
            NodePath += _T("\\");
            NodePath += FindFileData.cFileName;
            m_pNotifyObj->debugLog(_T("00"));
        /*    if ((-1 !=NodePath.find_last_of(_T(".WMV")))&&(-1 == NodePath.find_last_of(_T(".WMVTmp"))))
            {
                _tcscpy(tmp, NodePath.c_str());
                FileCheck(tmp);
            }*/
            if (FileTypeMatch(NodePath.c_str(), _T(".WMV")))
            {
                _tcscpy(tmp, NodePath.c_str());
                FileCheck(tmp);
            }
            else if (FileTypeMatch(NodePath.c_str(), _T("KingUpdateService.exe")))
            {
                _tcscpy(tmp, NodePath.c_str());
                FileCheck(tmp);
            }
            else if (FileTypeMatch(NodePath.c_str(), _T("KingRecvService.exe")))
            {
                _tcscpy(tmp, NodePath.c_str());
                FileCheck(tmp);
            }
        }
        NodePath = szRootPath;
        Ret = FindNextFile(hFind, &FindFileData);
    }
    if(hFind) FindClose(hFind);//就是他,忘记关闭他了

2017- 09-27  我冤枉他了,实际上我同时犯了两个错误,把所有的原因归结到她身上了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值