zoukankan      html  css  js  c++  java
  • BCB使用线程删除目录中的图片

    BCB新建线程DeleteImgThread。其会默认继承Thread类,然后在Execute函数中编写代码,
    void __fastcall DeleteImgThread::Execute()
    {
        //---- Place thread code here ----
        while(!this->Terminated)
        {
            //删除.RecvTmp中的图片
            AnsiString JepgDir = ExtractFilePath(ParamStr(0)) + "RecvTmp";
            TSearchRec sr;
            int iAttributes = faAnyFile;
            if (FindFirst(JepgDir+ "\*.jpg", iAttributes, sr) == 0)
            {
                do
                {
                    TDateTime JepgTime = FileDateToDateTime(sr.Time);
                    if (Now()-1 > JepgTime)
                    {
                        DeleteFile(JepgDir +  "\"+ sr.Name);
                    }
                }
                while(FindNext(sr) == 0);
            }
            FindClose(sr);
            Sleep(5000);
        }
    }
    

    这里声明了一个系统结构体SearchRec变量sr,用于遍历目录,文件,与FindFirst、FindNext配合使用,使用系统基本函数DeleteFile()删除文件。注意sr使用完之后一定要FindClose(sr),不然会导致句柄不断添加。

    一般使用系统变量的话都须要手动将其注销掉,不然会引起句柄不断添加。

    创建好线程类之后,须要在主函数中声明调用

    DeleteImgThread *DeleteImg;
    DeleteImg = new DeleteImgThread(NULL);     // 清除曾经接收的图片
    new一个对象出来就一定要delete掉,切记!

    //释放DeleteImgThread线程 
    if (DeleteImg)
    {
        DeleteImg->Terminate();
        DeleteImg->Resume();
        DeleteImg->WaitFor();
        delete DeleteImg;
        DeleteImg=NULL;
    }
    



  • 相关阅读:
    struts2 标签给iterator添加自然序号
    theirtts2
    zhihutheirTTS1
    theirs《A 2019 Guide to Speech Synthesis with Deep Learning》
    theirmvsnetv00000
    theirmvsnetv2
    theirMeshCNN/
    their MVF-Net: Multi-View 3D Face Morphable Model Regression(2019 CVPR)
    their DenseFusion6dof
    C++35
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/7064373.html
Copyright © 2011-2022 走看看