VBA Code to Copy Files from one folder to another
FilesPath=inputbox("Enter Sourcepath for files to be copied as C:\RootFilesPath")
FileToCopyPath=inputbox("Enter destination folderpath to copy files Sample as C:\ODC Data Compare\ODC File Compare\Prod Data")
Set FileObj=createobject("Scripting.FileSystemObject")
If FileObj.FolderExists(FIlesPath) Then
Set oFolder=FileObj.GetFolder(FIlesPath)
Set oFiles=oFolder.Files
For each oFile in oFiles
FileName=oFile.name
FLName=split(FileName,"-")
FName=trim(FindRecid(FLName(0)))
If FileObj.FolderExists(FileToCopyPath) Then
Set DestRootFolder=FileObj.GetFolder(FileToCopyPath)
Set SubFolder=DestRootFolder.SubFolders
For each oFolder in SubFolder
SubFolderName=trim(oFolder.Name)
If SubFolderName=FName Then
SourcePath=FIlesPath & "\" & FileName
DestinationPath=FileToCopyPath & "\" & SubFolderName & "\"
FileObj.CopyFile SourcePath,DestinationPath,True
end if
Next
End If
Next
Set FileObj=nothing
msgbox "File copy process is completed"
End If
Public Function FindRecid(StrData)
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "[\d]+"
Set objMatch=objRegExp.execute(StrData)
For each Match in objMatch
FindRecid=match.value
Next
set objRegExp=nothing
End Function
Comments
Post a Comment