å¨VB代ç è¾å
¥åºå¤å¶ä¸é¢ä»£ç ï¼è¿è¡å³å¯ã
Option Explicit
Dim SrcFolder As String, DstFolder As String, FileName As String, S As String
Dim fs, folder, subfolders, Files, File, i, j
Public Function CreateDirectory(ByVal strPath As String) As Boolean
Dim i As Integer
Dim CurrentDir As String
On Error GoTo err
Dim strT() As String
If Dir(strPath, vbDirectory) <> "" Then
'å¦æç®å½åå¨,ç´æ¥è¿å
CreateDirectory = True
Exit Function
End If
If Dir(strPath) <> "" Then Exit Function
If Right(strPath, 1) = "\\" Then
'å»ææå³è¾¹ç""
strPath = Left(strPath, Len(strPath) - 1)
End If
If InStr(strPath, "\\") = 0 Then Exit Function
'æ åç®å½
strT = Split(strPath, "\\")
CurrentDir = strT(0)
For i = 1 To UBound(strT)
If Dir(CurrentDir & "\\" & strT(i), vbDirectory) = "" Then
MkDir CurrentDir & "\\" & strT(i)
CurrentDir = CurrentDir & "\\" & strT(i)
End If
Next
CreateDirectory = True
Exit Function
err:
'æ¤å¤å¦æåºéï¼å¾æå¯è½å°±æ¯ç®å½åä¸å
å«äºç³»ç»ä¸æ¯æçå符ï¼æ¯å¦è¯´* / & ç
End Function
Function digui(path)
Set folder = fs.GetFolder(path)
Set subfolders = folder.subfolders
Set Files = folder.Files
For Each i In Files
If InStr(1, i.Name, FileName, 1) Then 'å¦æåç°ç¬¦åç¹å¾çæ件
S = Mid(i.path, InStr(i.path, "\\"))
S = Left(S, InStrRev(S, i.Name, , vbTextCompare) - 1)
If Right(S, 1) = "\\" Then S = Left(S, Len(S) - 1)
S = DstFolder & S
CreateDirectory S
FileCopy i.path, S & "\\" & i.Name 'åå¤å¶
End If
DoEvents
Next
For Each j In subfolders
digui (j.path)
DoEvents
Next
End Function
Private Sub Form_Load()
SrcFolder = InputBox("请è¾å
¥æºç", "第1æ¥", "D:")
If SrcFolder = "" Then End
DstFolder = InputBox("请è¾å
¥ç®æ ç", "第2æ¥", "E:")
If DstFolder = "" Then End
If Right(DstFolder, 1) = "\\" Then DstFolder = Left(DstFolder, Len(DstFolder) - 1)
FileName = InputBox("请è¾å
¥æ件åç¹å¾", "第3æ¥", ".Mp3")
If FileName = "" Then End
FileName = Replace(FileName, "*", "")
Set fs = CreateObject("scripting.filesystemobject")
digui (SrcFolder)
MsgBox "æ件å¤å¶ç»æï¼", vbInformation, "æåä½ "
End
End Sub
温馨提示:答案为网友推荐,仅供参考