08 November 2017

Function to copy files from one Folder to another based on their Extension like .txt, .bmp, .docx using VB Script

SF = "C:\Copy\SF\" 'Source Folder
DF = "C:\Copy\DF\" 'Destination Folder

Call CopyFiles(SF, DF, "txt")


'Function to copy Files based on their extension
Function CopyFiles(SF, DF, Ext)

    'SF = Source Folder
    'DF = Destination Folder
    'Ext = Extension like txt, bmp, docx
    'Example - Call CopyFiles("C:\Copy\SF\", "C:\Copy\DF\", "txt")
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fol1 = fso.GetFolder(SF)
    Set fis = fol1.Files

    For Each fs In fis

    fname = fs.Name
            
        If Ext = fso.GetExtensionName(fname) Then
            fso.CopyFile SF&fname, DF
        End If
    
    Next

End Function



...

No comments:

Post a Comment

AOM - Automation Object Model

'Creating QuicTest Object Set  qtapp =  createobject ( "QuickTest.Application" ) 'Launching the Application If  qtapp...