hi everyone,
I now its a mainstream thing that I am writing now in fso systems but I am trying to learn "how I would do that" thing, can you please help with the below code?
It does not give any error message or something but it is not copying any materials to destination.
I now its a mainstream thing that I am writing now in fso systems but I am trying to learn "how I would do that" thing, can you please help with the below code?
It does not give any error message or something but it is not copying any materials to destination.
Code:
Sub copy_specificextension_files_in_folder()
Dim FSO As Object
Dim sourcePath As String
Dim destinationPath As String
Dim fileExtn As String
sourcePath = "\\::"
destinationPath = "C:\"
fileExtn = "*.pdf*"
If Right(sourcePath, 1) <> "\" Then
sourcePath = sourcePath & "\"
End If
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(sourcePath) = False Then
MsgBox sourcePath & " does not exist "
End If
Exit Sub
If FSO.FolderExists(destinationPath) = False Then
MsgBox destinationPath & " does not exist "
End If
Exit Sub
If FSO.FileExists(sourcePath) = False Then
copy_files_from_subfolders
Else
FSO.copyfile Source:=sourcePath & fileExtn, Destination:=destinationPath
End If
MsgBox "Your files have been copied from " & sourcePath & "to" & destinationPath
End Sub
Sub copy_files_from_subfolders()
Dim FSO As Object, fld As Object
Dim fsoFile As Object
Dim fsoFol As Object
sourcePath = "\\::"
targetPath = "C:\"
If Right(sourcePath, 1) <> "\" Then
sourcePath = sourcePath & "\"
End If
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fld = FSO.GetFolder(sourcePath)
If FSO.FolderExists(fld) Then
For Each fsoFol In FSO.GetFolder(sourcePath).SubFolders
For Each fsoFile In fsoFol.Files
If Right(fsoFile, 3) = "pdf" Then
fsoFile.Copy targetPath
End If
Next
Next
End If
End Sub