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);

  • 相关阅读:
    Could A New Linux Base For Tablets/Smartphones Succeed In 2017?
    使用libhybris,glibc和bionic共存时的TLS冲突的问题
    6 Open Source Mobile OS Alternatives To Android in 2018
    Using MultiROM
    GPU drivers are written by the GPU IP vendors and they only provide Android drivers
    Jolla Brings Wayland Atop Android GPU Drivers
    How to Use Libhybris and Android GPU Libraries with Mer (Linux) on the Cubieboard
    闲聊Libhybris
    【ARM-Linux开发】wayland和weston的介绍
    Wayland and X.org problem : Why not following the Android Solution ?
  • 原文地址:https://www.cnblogs.com/feisky/p/1586480.html
Copyright © 2011-2022 走看看