Hi.
I have the below VBA script that will copy .csv files from multiple subfolders into 1 folder. It works great if the file names are unique but if I have any that are the same it won't generate a copy.
Can anyone help me modify the script to allow it bring in duplicates csv files.
example below:
Scrape Results 02-03 - 0114PM
Scrape Results 02-03 - 0114PM (so the second file it which has same name can it put a (1) on the end instead of ignoring it)
Code:
I have the below VBA script that will copy .csv files from multiple subfolders into 1 folder. It works great if the file names are unique but if I have any that are the same it won't generate a copy.
Can anyone help me modify the script to allow it bring in duplicates csv files.
example below:
Scrape Results 02-03 - 0114PM
Scrape Results 02-03 - 0114PM (so the second file it which has same name can it put a (1) on the end instead of ignoring it)
Code:
VBA Code:
Sub copy_files_from_subfolders()
Dim FSO As Object, fld As Object
Dim fsoFile As Object
Dim fsoFol As Object
SourcePath = "C:\Users\dan\Desktop\zz"
targetPath = "C:\Users\dan\Documents\splitmerge\"
If Right(SourcePath, 1) <> "\" Then SourcePath = SourcePath & "\"
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) = "csv" Then
fsoFile.Copy targetPath
End If
Next
Next
End If
End Sub