Tuesday, 5 February 2013

Compare the Files based on Date Modified and Move the file with earlier timestamp to a specified folder

Compare the Files based on Date Modified and Move the file with earlier timestamp to a specified folder
(Added the reporter event.. + File exists Check)
 
Dim f1
Set fso = CreateObject("Scripting.FileSystemObject")
strPendingFolder =  "
\\tstgnpappw001\IVS_ Automation\Project THOR\Incoming\"

               
If fso.FolderExists(strPendingFolder) Then
  Set fileList = fso.GetFolder(strPendingFolder).Files
  filecount = fileList.Count
    If  filecount = 0 Then
  Reporter.ReportEvent micWarning,"No Files Present in  Incomming Folder","Files not found in
\\tstgnpappw001\IVS_ Automation\Project THOR\Incoming\    location"
       ExitRun                                                                                                                                   End If
Else
   Reporter.ReportEvent micWarning,"No Incomming Folder Present ","Incoming Folder not found in
\\tstgnpappw001\IVS_ Automation\Project THOR\"
 ExitRun
End If

For Each f1 in fileList
   filename=  f1.name
   filetime = f1.DateCreated
   new_line  = split(filetime," ")
     date_revised = split(new_line(0),"/")
  new_date=date_revised(0)&date_revised(1)&date_revised(2)
  time_revised = split(new_line(1),":")
  new_time = time_revised(0)&time_revised(1)&time_revised(2)
 final_output_creationtime = new_date&new_time
 collective_filename = collective_filename&"_"&filename
 saveme = saveme&"_"&final_output_creationtime
Next

 split_filetime = split(saveme, "_")
 split_filename = split(collective_filename,"_")
 For i = 1 to ubound(split_filetime)
  refernce_file = split_filetime(1)
          If  refernce_file > split_filetime(i)Then
        refernce_file = split_filetime(i)
     reference_filename = split_filename(i)
    End If
Next
                               
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(strPendingFolder & "\" & reference_filename )
fso.MoveFile  f,strResponseFileFolder
 

2 comments:

  1. Thank you for giving me great knowledge about QTP. It helps people who struggling with QTP.

    ReplyDelete