Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading folder
#1
Solved: 11 Years, 3 Months, 2 Weeks ago
Hi there,

I have a situation where I have to create a specific file and put it into a folder.

I need to get the file name from this file and then use this file name to search on a webtable after it has been uploaded into my application I am testing.

I created scripts for the creating the file and searching the webtable for the value

My idea is to place this file into a folder and have QTP read the name of this file and pass that value to the function that searches the webtable.

How do I achieve the part that reads the folder for the file name?

I cant hardcode the filename as I never know what it will be...

Thanks!
Reply
#2
Solved: 11 Years, 3 Months, 2 Weeks ago
Hi Jove,

You can develop a recursive function to go through the folders and pickup the absolute path to the desired folder and then you can pass that to you function.

Please let me know if you need help in developing the recursive function.

Let me know if you have any more questions or need more info.
Thanks,
SUpputuri
Reply
#3
Solved: 11 Years, 3 Months, 2 Weeks ago
As there will only ever be one file in the folder this is what i did, guess i could drop the for loop from this example.
Code:
Dim oFolder, sOut, oFSO, callnr
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:\calls")
Set oFilesCol = oFolder.Files
For Each oFile in oFilesCol
'MsgBox oFile.Name, oFile.Size
callnr = oFile.Name
msgbox callnr
Next

thanks!
Reply
#4
Solved: 11 Years, 3 Months, 2 Weeks ago
Hi,
Are the folder name and path or static or dynamic. If they are static then you can go-a-head with the code that you have developed (But Validate the File Name, then only exit the loop :-)), else you have to go with the recursive function.
Thanks,
SUpputuri
Reply
#5
Solved: 11 Years, 3 Months, 2 Weeks ago
Hi Supputuri,

thanks for your help. The folder location is static and I planned to have only one file in there at one time. You see the file contains a number of tab seperated text blocks one entry is a callid - which i need to search for in the system once this file has been uploaded. I am searching on a specific screens webtable.

To make life easier i just named the file by this callid.

It kind of restricts me to just having one file in the folder at any one time, which cant be good. Do you have any other suggestions?

I know that the call id is 10 characters into the text file and the callnr is 9 characters long. How do I read this from the file?

Even though what I did above will do for the short term, do you have any other suggestions to my problem?
Reply
#6
Solved: 11 Years, 3 Months, 2 Weeks ago
Hi,
I have posted some time back related to this kind of query but not exactly same. I hope it will helps you below code. Dont follow exact code. I just gave for your reference for reading file from folder.

For details refer below link:

https://www.learnqtp.com/forums/Thread-H...t=function

Code:
Function GetNewestFile(ByVal sPath)

   sNewestFile = Null   ' init value

   Set oFSO = CreateObject("Scripting.FileSystemObject")
   Set oFolder = oFSO.GetFolder(sPath)
   Set oFiles = oFolder.Files

   ' enumerate the files in the folder, finding the newest file
   For Each oFile In oFiles
     On Error Resume Next
     If IsNull(sNewestFile) Then
       sNewestFile = oFile.Path
       dPrevDate = oFile.DateLastModified
     Elseif dPrevDate < oFile.DateLastModified Then
       sNewestFile = oFile.Path
     End If
     On Error Goto 0
   Next

   If IsNull(sNewestFile) Then sNewestFile = ""

   GetNewestFile = sNewestFile

End Function
sPath = "c:\my test"  'Here my test is the folder name
Set oFSO = CreateObject("Scripting.FileSystemObject")
sNewestFile = GetNewestFile(sPath)
If sNewestFile <> "" Then
   WScript.Echo "Newest file is " & sNewestFile
Else
   WScript.Echo "Directory is empty"
End If
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading Global Sheet's DataTable Value Bhuvana 0 1,622 01-05-2020, 10:03 PM
Last Post: Bhuvana
  Executing via create "RES"xx folder? nishitd 0 1,231 03-07-2018, 01:09 AM
Last Post: nishitd
  Reading Value from Java Table arjun.singh 8 24,322 10-11-2017, 02:51 PM
Last Post: sivaji
  Reading data from excel sheet serenediva 1 9,557 03-03-2017, 10:07 AM
Last Post: vinod123
  code for validation to create a sub folder smiley 0 1,521 10-19-2016, 10:08 PM
Last Post: smiley

Forum Jump:


Users browsing this thread: 1 Guest(s)