Micro Focus QTP (UFT) Forums
Recently Created File or Folder - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Recently Created File or Folder (/Thread-Recently-Created-File-or-Folder)



Recently Created File or Folder - bfakruddin - 12-22-2009

Hello Folks,

Can anybody tell how to get the recently created Folder or a File in a Parent Folder...

Please give me the code

Thanks & regards
Baba Fakruddin.D


RE: Recently Created File or Folder - sreekanth chilam - 12-22-2009

Hi ,

Try with the below code for your query "How to get the files in a parent folder?"

Code:
Set objFileSysOb = CreateObject("Scripting.FileSystemObject")
Set colFolderName = objFileSysOb.GetFolder("Give your Parent Folder path here")
Set vFiles =colFolderName.Files
For each i in vFiles
   d=Split(i,"\")
   FileName=d(ubound(d))
   msgbox FileName
Next



RE: Recently Created File or Folder - bfakruddin - 12-28-2009

Thank You Sreekanth,

Nice Script... But, I need the file recently created....! because I need to get the data from that file. I don't want to provide that file name externally.
I think we can get that file by using "FileSystemObject"... But, I don't know which method need to use to get recently created file(Latest File in that folder)

Thanks & regards
Baba Fakruddin.D


RE: Recently Created File or Folder - jsknight1969 - 12-29-2009

Then just add the code for it

Code:
Set objFileSysOb = CreateObject("Scripting.FileSystemObject")
Set colFolderName = objFileSysOb.GetFolder("Give your Parent Folder path here")
Set vFiles =colFolderName.Files
dim f, datecreated, lastfilename
For each i in vFiles
   FileName=d(ubound(d))
   f = objFileSysOb.GetFile(FileName)
   if datecreated = "" then
     datecreated = f.DateCreated
     lastfilename = FileName
   else
      'check lastdate to current file
      if datecreated < f.DateCreated then
         datecreated = f.DateCreated
         lastfilename = FileName
      end if
   end if
Next
msgbox "Last file created was " & lastfilename

This code may not be perfect, but by storing and comparing the file created dates you should find the last file created then store the filename. Might have to cast the date variables to get them to compare as dates correctly.
[/code]