Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recently Created File or Folder
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
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
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
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
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
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
Reply
#4
Solved: 11 Years, 4 Months, 3 Weeks ago
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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a folder from within a reusable action. sd3 2 3,235 06-18-2013, 03:20 PM
Last Post: learnQtptips
  How can i write a script in QTP to poll a folder for a new file? geethwind 5 5,571 05-19-2011, 07:04 PM
Last Post: deepaksporty
  Open lastmodified file in a folder vimal singh 1 2,226 04-26-2010, 05:02 PM
Last Post: manishbhalshankar
  Reusable Actions created in 9.2 not recognized in 9.5 varsi 1 2,515 04-06-2010, 03:26 PM
Last Post: funajju
  How to connect to Linux m/c from QTP script for validatating the new created dir rao 1 3,200 07-23-2009, 12:51 PM
Last Post: QTPian

Forum Jump:


Users browsing this thread: 1 Guest(s)