小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

vc對(duì)文件夾的操作SHFileOperation()的使用【轉(zhuǎn)】

 tianht 2015-04-24

轉(zhuǎn)自http://www./news/1007/444817.html

SHFileOperations刪除操作,pFrom接受變量傳值時(shí)老是出錯(cuò),搞了一晚上沒(méi)查出原因,還好查到這位同學(xué)的資料,手工在字符串后面加2個(gè)'\0',就可以了,如果是直接手寫(xiě)路徑,微軟庫(kù)自動(dòng)作此處理了。

 SHFileOperation()函數(shù)主要對(duì)文件夾有四種操作:復(fù)制,刪除,移動(dòng),重命名。

  擠時(shí)間對(duì)這個(gè)函數(shù)進(jìn)行了利用了一下。寫(xiě)了四個(gè)函數(shù)??梢院芎玫膶?duì)文件夾進(jìn)行操作。

  /////////////////////////////////////

  //函數(shù)名:DeleteFolder

  //輸入?yún)?shù):LpszPath 要?jiǎng)h除的路徑指針

  //作用:刪除指定文件夾以及里面的文件

  //

  /////////////////////////////////////

  BOOL DeleteFolder(LPCTSTR lpszPath)

  {

  int nLength = strlen(lpszPath);

  char *NewPath = new char[nLength+2];

  strcpy(NewPath,lpszPath);

  NewPath[nLength] = '\0';

  NewPath[nLength+1] = '\0';

  SHFILEOPSTRUCT FileOp;

  ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));

  FileOp.fFlags = FOF_NOCONFIRMATION;

  FileOp.hNameMappings = NULL;

  FileOp.hwnd = NULL;

  FileOp.lpszProgressTitle = NULL;

  FileOp.pFrom = NewPath;

  FileOp.pTo = NULL;

  FileOp.wFunc = FO_DELETE;

  return SHFileOperation(&FileOp) == 0;

  }

  /////////////////////////////////////

  //函數(shù)名:CopyFolder

  //參數(shù):lpszFromPath 源文件夾的路徑 。 lpszToPath 目的文件夾的路徑

  //作用:拷貝文件夾及其文件夾中的所有內(nèi)容

  //

  //////////////////////////////////////

  BOOL CopyFolder(LPCTSTR lpszFromPath,LPCTSTR lpszToPath)

  {

  int nLengthFrm = strlen(lpszFromPath);

  char *NewPathFrm = new char[nLengthFrm+2];

  strcpy(NewPathFrm,lpszFromPath);

  NewPathFrm[nLengthFrm] = '\0';

  NewPathFrm[nLengthFrm+1] = '\0';

  SHFILEOPSTRUCT FileOp;

  ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));

  FileOp.fFlags = FOF_NOCONFIRMATION ;

  FileOp.hNameMappings = NULL;

  FileOp.hwnd = NULL;

  FileOp.lpszProgressTitle = NULL;

  FileOp.pFrom = NewPathFrm;

  FileOp.pTo = lpszToPath;

  FileOp.wFunc = FO_COPY;

  return SHFileOperation(&FileOp) == 0;

  }
 

  /////////////////////////////////////

  //函數(shù)名:MoveFolder

  //參數(shù):lpszFromPath 源文件夾路徑 。lpszToPath 目的文件夾路徑

  //作用:移動(dòng)原文件夾及其中文件都指定的路徑下

  //

  /////////////////////////////////////

  BOOL MoveFolder(LPCTSTR lpszFromPath,LPCTSTR lpszToPath)

  {

  int nLengthFrm = strlen(lpszFromPath);

  char *NewPathFrm = new char[nLengthFrm+2];

  strcpy(NewPathFrm,lpszFromPath);

  NewPathFrm[nLengthFrm] = '\0';

  NewPathFrm[nLengthFrm+1] = '\0';

  SHFILEOPSTRUCT FileOp;

  ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));

  FileOp.fFlags = FOF_NOCONFIRMATION ;

  FileOp.hNameMappings = NULL;

  FileOp.hwnd = NULL;

  FileOp.lpszProgressTitle = NULL;

  FileOp.pFrom = NewPathFrm;

  FileOp.pTo = lpszToPath;

  FileOp.wFunc = FO_MOVE;

  return SHFileOperation(&FileOp) == 0;

  }

  /////////////////////////////////////

  //ReNameFolder

  //參數(shù):lpszFromPath 源文件夾路徑 。lpszToPath 目的文件夾路徑

  //作用:修改原文件夾的名字。

  //

  /////////////////////////////////////

  BOOL ReNameFolder(LPCTSTR lpszFromPath,LPCTSTR lpszToPath)

  {

  int nLengthFrm = strlen(lpszFromPath);

  char *NewPathFrm = new char[nLengthFrm+2];

  strcpy(NewPathFrm,lpszFromPath);

  NewPathFrm[nLengthFrm] = '\0';

  NewPathFrm[nLengthFrm+1] = '\0';

  SHFILEOPSTRUCT FileOp;

  ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));

  FileOp.fFlags = FOF_NOCONFIRMATION ;

  FileOp.hNameMappings = NULL;

  FileOp.hwnd = NULL;

  FileOp.lpszProgressTitle = NULL;

  FileOp.pFrom = NewPathFrm;

  FileOp.pTo = lpszToPath;

  FileOp.wFunc = FO_RENAME;

  return SHFileOperation(&FileOp) == 0;

  }

  這四個(gè)函數(shù)在VC6.0下通過(guò)測(cè)試了一下,效果還是有的。不過(guò)感覺(jué),F(xiàn)O_RENAME和FO_MOVE有點(diǎn)相似,而且是作用十分相似。
轉(zhuǎn)自:<a href='http://www./jsjks/'>計(jì)算機(jī)培訓(xùn)網(wǎng)</a>

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多