VB通过扩展复制特定文件

时间:2014-03-20 23:18:36

标签: windows vb6 text-files

任何人都可以给我任何关于下面脚本的指示我想尝试创建,基本上我尝试搜索父项下的某些文件夹,但是一般的子结构大致相同,如果存在则复制某些扩展名,但并非所有子文件夹中都存在所有扩展名

当我运行脚本时,我没有将任何文件复制到"收获"文件夹或任何子文件在Harvest文件夹下创建的文件夹,文件夹和文件都在测试此脚本时存在

任何帮助非常感谢

advancedPath = InputBox("Type the Application Sharepoint")
advancedDBPath = InputBox("Type the Database Folder")
harvestFolder = InputBox("Type the Harvest Folder")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = WScript.CreateObject( "WScript.Shell" )

' Check if Harvest folder exist if not create
If Not objFSO.FolderExists(harvestFolder) Then
objFSO.CreateFolder(harvestFolder)
End If

'Extensions to copy
extStr = Array("*.ini", "*.pf","*.bat","*.admin","*.st","*.ver","*.propath")

If objFSO.FolderExists(advancedPath & "oalive80") Then
' Check if Oalive80 exist   
If objFSO.FolderExists(advancedPath & "oalive80") = TRUE Then
 objFSO.CreateFolder(harvestFolder & "oalive80")
 objFSO.CopyFile advancedPath & "oalive80" & "\"  & extStr, harvestFolder & "oalive80", false
 objFSO.CopyFile advancedPath & "oalive80\oahfb10" & "\"  & extStr, harvestFolder & "oalive80", false
End If

' Check if Oatest80 exist   
If objFSO.FolderExists(advancedPath & "oatest80") = TRUE Then
 objFSO.CreateFolder(harvestFolder & "oatest80")
 objFSO.CopyFile advancedPath & "oatest80" & "\"  & extStr, harvestFolder & "oatest80", false
End If

' Check if oplive exist     
If objFSO.FolderExists(advancedPath & "oplive") = TRUE Then
 objFSO.CreateFolder(harvestFolder " "oplive")
 objFSO.CopyFile advancedPath & "oplive\gclib\pf" & "\" & extStr, harvestFolder & "oplive" false
End If

' Check if Live DB folder exist     
If objFSO.FolderExists(advancedDBPath & "oalive80") = TRUE Then
 objFSO.CreateFolder(harvestFolder & "LiveDB")
 objFSO.CopyFile advancedDBPath & "oalive80\oa_data" & "\" & extStr, harvestFolder & "LiveDB", false
End If

End If

1 个答案:

答案 0 :(得分:0)

对于每个复制代码

,您应该为数组使用循环,如下所示
  For iCt = 0 To UBound(extStr)
    strExtn = extStr(iCt)
    objFSO.CopyFile advancedPath & "oalive80" & "\"  & strExtn , harvestFolder & "oalive80", false
  Next

也许使用如下所示的函数代码:

Private Sub BulkCopyFile(ByVal objFSO As Scripting.FileSystemObject, ByVal strSourceFolder As String, ByVal strDestinationFolder As String)
  extStr = Array("*.ini", "*.pf","*.bat","*.admin","*.st","*.ver","*.propath")
  For iCt = 0 To UBound(extStr)
    strExtn = extStr(iCt)
    objFSO.CopyFile strSourceFolder & strExtn, strDestinationFolder, False
  Next
End Sub

代码的使用示例

' Check if Oalive80 exist
If objFSO.FolderExists(advancedPath & "oalive80") = True Then
  objFSO.CreateFolder (harvestFolder & "oalive80")
  Call BulkCopyFile(objFSO, advancedPath & "oalive80" & "\", harvestFolder & "oalive80")
  Call BulkCopyFile(objFSO, advancedPath & "oalive80\oahfb10" & "\", harvestFolder & "oalive80")
End If