zoukankan      html  css  js  c++  java
  • 删除 复制文件夹

    删除:
    void COperationDlg::OnDel2(CString m_strFileDictory) //参数就是目录的路径
    {
    if(m_strFileDictory.GetLength()==0)
    {
    ::AfxMessageBox (”目录名非法!”,MB_OK|MB_ICONEXCLAMATION);
    return;
    }
    char FromFileName[80]=”";
    strcpy(FromFileName,m_strFileDictory);
    strcat(FromFileName,”");
    SHFILEOPSTRUCT lpFileOp;
    lpFileOp.hwnd =GetSafeHwnd();
    lpFileOp.wFunc =FO_DELETE;
    lpFileOp.pFrom =FromFileName;
    lpFileOp.pTo=NULL;
    lpFileOp.fFlags =FOF_SILENT|FOF_NOCONFIRMATION;
    lpFileOp.fAnyOperationsAborted =FALSE;
    lpFileOp.hNameMappings =NULL;
    lpFileOp.lpszProgressTitle =NULL;
    int rval=SHFileOperation(&lpFileOp);
    if(rval==0)
    {
    if(lpFileOp.fAnyOperationsAborted ==TRUE)
    ::AfxMessageBox (”删除目录操作取消”,MB_OK);
    else
    ::AfxMessageBox(”删除目录操作成功!”,MB_OK|MB_ICONEXCLAMATION);
    }
    else
    {
    ::AfxMessageBox (”删除目录操作失败!”,MB_OK|MB_ICONEXCLAMATION);
    }
    }

    拷贝
    BOOL CCutfoldDlg::CopyDirectory(CString SourcePath,CString CopytoPath)
    {
    CFileFind tempFind;
    char tempFileFind[200];
    char tempFileFind1[200];

    SECURITY_ATTRIBUTES lpSecurityDescriptor;
    CreateDirectory(CopytoPath,&lpSecurityDescriptor);

    sprintf(tempFileFind1,”%s\\*.*”,CopytoPath);
    sprintf(tempFileFind,”%s\\*.*”,SourcePath);

    BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
    // BOOL IsFinded1=(BOOL)tempFind.FindFile(tempFileFind1);
    while(IsFinded)
    {
    IsFinded=(BOOL)tempFind.FindNextFile();
    if(!tempFind.IsDots())
    {
    char foundFileName[200];
    // char foundFileName1[200];
    strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
    // strcpy(foundFileName1,tempFind.GetFileName().GetBuffer(200));
    if(tempFind.IsDirectory())
    {
    char tempDir[200];
    char tempDir1[200];
    sprintf(tempDir,”%s\\%s”,SourcePath,foundFileName);
    sprintf(tempDir1,”%s\\%s”,CopytoPath,foundFileName);
    CopyDirectory(tempDir,tempDir1);
    }
    else
    {
    char tempFileName[200];
    char tempFileName1[200];
    sprintf(tempFileName,”%s\\%s”,SourcePath,foundFileName);
    sprintf(tempFileName1,”%s\\%s”,CopytoPath,foundFileName);
    //DeleteFile(tempFileName);
    CopyFile(tempFileName,tempFileName1,0);
    }
    }
    }
    tempFind.Close();
    return TRUE;
    }

    要实现移动,遍历文件+MoveFile+CreateDirectory
    遍历方法参考:
    HANDLE hFind;
    WIN32_FIND_DATA dataFind;
    BOOL bMoreFiles=TRUE;
    hFind=FindFirstFile(sPath+”\\*.txt”,&dataFind);////sPath表示路径
    while(hFind!=INVALID_HANDLE_VALUE && bMoreFiles==TRUE)
    {
    if(dataFind.dwFileAttributes==FILE_ATTRIBUTE_ARCHIVE)
    {
    MessageBox(dataFind.cFileName);
    }
    bMoreFiles=FindNextFile(hFind,&dataFind);
    }
    FindClose(hFind);

  • 相关阅读:
    TP5.1 分页CSS样式(转载)
    简单的layui二级联动
    关于layui部分表单不显示的问题(Select, checkBox)
    MySQL 开启远程访问权限 | 宝塔系统
    tp5.1 本地正常, 线上route.php不起作用的问题
    cocos自动图集
    微信小程序video
    nuxt https
    接口数据加密
    node里读取命令行参数
  • 原文地址:https://www.cnblogs.com/feisky/p/1586520.html
Copyright © 2011-2022 走看看