Guest User

Untitled

a guest
Jan 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. Dim FSO As Object
  2. Dim FromPath As String
  3. Dim ToPath As String
  4. Dim Fdate As Date
  5. Dim FileInFromFolder As Object
  6.  
  7. FromPath = "H:testfrom"
  8. ToPath = "H:testto"
  9.  
  10. Set FSO = CreateObject("scripting.filesystemobject")
  11. For Each FileInFromFolder In FSO.getfolder(FromPath).Files
  12. Fdate = Int(FileInFromFolder.DateLastModified)
  13. If Fdate >= Date - 1 Then
  14.  
  15. FileInFromFolder.Copy ToPath
  16.  
  17. End If
  18. Next FileInFromFolder
  19. End Sub
  20.  
  21. Public Sub PerformCopy()
  22. CopyFiles "H:testfrom", "H:testto"
  23. End Sub
  24.  
  25.  
  26. Public Sub CopyFiles(ByVal strPath As String, ByVal strTarget As String)
  27. Set FSO = CreateObject("scripting.filesystemobject")
  28. 'First loop through files
  29. For Each FileInFromFolder In FSO.getfolder(strPath).Files
  30. Fdate = Int(FileInFromFolder.DateLastModified)
  31. If Fdate >= Date - 1 Then
  32. FileInFromFolder.Copy strTarget
  33. End If
  34. Next FileInFromFolder
  35.  
  36.  
  37. 'Next loop throug folders
  38. For Each FolderInFromFolder In FSO.getfolder(strPath).SubFolders
  39. CopyFiles FolderInFromFolder.Path, strTarget
  40. Next Folder
  41. End Sub
  42.  
  43. Private Sub Command3_Click()
  44.  
  45. Dim objFSO As Object 'FileSystemObject
  46. Dim objFile As Object 'File
  47. Dim objFolder As Object 'Folder
  48. Const strFolder As String = "H:testfrom2"
  49. Const strNewFolder As String = "H:testto"
  50. Set objFSO = CreateObject("Scripting.FileSystemObject")
  51. For Each objFolder In objFSO.GetFolder(strFolder & "").SubFolders
  52. 'If Right(objFolder.Name, 2) = "tb" Then
  53. For Each objFile In objFolder.Files
  54. 'If InStr(1, objFile.Type, "Excel", vbTextCompare) Then
  55. On Error Resume Next
  56. Kill strNewFolder & "" & objFile.Name
  57. Err.Clear: On Error GoTo 0
  58.  
  59. Name objFile.Path As strNewFolder & "" & objFile.Name
  60. 'End If
  61. Next objFile
  62. 'End If
  63. Next objFolder
  64.  
  65.  
  66. End Sub
  67.  
  68. ==================== call ================================
  69. MkDir "DestinationPath"
  70.  
  71. CopyFiles "SourcePath" & "", "DestinationPath" & ""
  72.  
  73. ==================== Copy sub ===========================
  74.  
  75. Public Sub CopyFiles(ByVal strPath As String, ByVal strTarget As String)
  76. Dim FSO As Object
  77. Dim FileInFromFolder As Object
  78. Dim FolderInFromFolder As Object
  79. Dim Fdate As Long
  80. Dim intSubFolderStartPos As Long
  81. Dim strFolderName As String
  82.  
  83. Set FSO = CreateObject("scripting.filesystemobject")
  84. 'First loop through files
  85. For Each FileInFromFolder In FSO.GetFolder(strPath).Files
  86. Fdate = Int(FileInFromFolder.DateLastModified)
  87. 'If Fdate >= Date - 1 Then
  88. FileInFromFolder.Copy strTarget
  89. 'end if
  90. Next
  91.  
  92. 'Next loop throug folders
  93. For Each FolderInFromFolder In FSO.GetFolder(strPath).SubFolders
  94. 'intSubFolderStartPos = InStr(1, FolderInFromFolder.Path, strPath)
  95. 'If intSubFolderStartPos = 1 Then
  96.  
  97. strFolderName = Right(FolderInFromFolder.Path, Len(FolderInFromFolder.Path) - Len(strPath))
  98. MkDir strTarget & "" & strFolderName
  99.  
  100. CopyFiles FolderInFromFolder.Path & "", strTarget & "" & strFolderName & ""
  101.  
  102. Next 'Folder
  103.  
  104. End Sub
Add Comment
Please, Sign In to add comment