使用遍歷文件夾方法:這是我寫的復制方法,以下代碼放到線程掛起來復制會比較順才不會占cpu資源假死機狀態(tài)。DimopennameAsString'要復制的路徑DimsavennameAsString'保存的路徑DimLoadfilecount,MincountAsInteger'加載路徑復制文件PrivateSubLoadfile()Mincount=0Loadfilecount=0TryForEachfoundFileAsStringInMy.Computer.FileSystem.GetFiles_(openname)'遍歷當前目錄文件Mincount+=1copyfile(foundFile)NextForEachfoundDirectoryAsStringInMy.Computer.FileSystem.GetDirectories_(openname,FileIO.SearchOption.SearchAllSubDirectories)'遍歷所有文件夾ForEachfoundFileAsStringInMy.Computer.FileSystem.GetFiles_(foundDirectory)'遍歷所有文件名稱Mincount+=1copyfile(foundFile)NextNextCatchexAsExceptionMessageBox.Show(ex.Message)EndTryMsgBox("復制完成!"&Loadfilecount.ToString&"個",,"提示!")EndSub'''<summary>'''復制文件'''</summary>'''<paramname="Cpname">文件路徑和名稱</param>'''<remarks></remarks>PrivateSubcopyfile(ByValCpnameAsString)DimSanameAsString=""TryDimtnameAsStringDimPathnameAsStringPathname=My.Computer.FileSystem.GetParentPath(Cpname).Replace(openname,"")'獲取文件夾名稱tname=My.Computer.FileSystem.GetName(Cpname)DimNewpathnameAsStringNewpathname=savenname&PathnameIfMy.Computer.FileSystem.FileExists(Newpathname)=FalseThen'如果沒有文件夾則創(chuàng)建My.Computer.FileSystem.CreateDirectory(Newpathname)EndIfSaname=savenname&Pathname&"\"&tnameIfMy.Computer.FileSystem.FileExists(Saname)=TrueThen'如果文件存在去掉只讀。My.Computer.FileSystem.GetFileInfo(Saname).Attributes=0TryMy.Computer.FileSystem.CopyFile(Cpname,Saname,True)Loadfilecount+=1ListBox1.Items.Add(Cpname.Replace(openname,".."))CatchexAsExceptionMessageBox.Show("文件未更新,請關(guān)閉相關(guān)程序后重試!"&vbCrLf&Cpname,"警告!")EndTryElseMy.Computer.FileSystem.CopyFile(Cpname,Saname,True)Loadfilecount+=1EndIfCatchexAsExceptionEndTryEndSub
網(wǎng)站導航
- zblogPHP模板zbpkf
- zblog免費模板zblogfree
- zblog模板學習zblogxuexi
- zblogPHP仿站zbpfang