Forum Discussion

wynandb1's avatar
wynandb1
Contributor
9 years ago
Solved

Verify date in text file

Good day

 

I hope there is somebody that can help please ?

 

I have the following code that finds a text file exported by the tested application and reads a certain part of the file. This part is a date in yymmdd format in the text file exported from the tested application. There are no slashes or anything separating the date. It looks like this 150506

 

This date in the file should always be two days from today. So if the export is done today eg. 2015-05-06 , the date in the file should be 150508. The date in the file is located in line 3 column 59 to 64.

 

Could someone please help me to verify this date in the file ? 

 

Herewith the script. This is script that I got from a previous post. I would like to add the verify part to this script. I would also like to get some sort of confirmation that the date is indeed two days from today and if not I would like to get confirmation of that as well please. 

 

Thank you in advance

Wynand

 

function main(){
readfile("C:\\FolderName\\", "Name_Of_File_*_*");
}

function readfile(directory,filename){
var foundFiles = aqFileSystem.FindFiles(directory, filename);
if (foundFiles != null) {
if (foundFiles.Count == 1) {
var sPath = foundFiles.Next().Path;
ReadDateFromFile(sPath);
}
else {
Log.Error("More than 1 file found.");
}
}
else {
Log.Error("File not found.");
}
}

function ReadDateFromFile(sPath){
var sPath = sPath;

// Opens the specified file for reading
var myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI);

// Skips to the specifed position and reads the specified amount of symbols
myFile.SkipLine(2);
myFile.Skip(58);
var sDate = myFile.ReadString(6);

// Closes the file
myFile.Close();
}

  • Awesome!!

     

    Can't thank you enough!!

     

    Thanks a lot for the help!! 

4 Replies

  •  

    Try this after setting sDate:

     

    var dDate = aqDateTime.SetDateElements(2000+(sDate.substr(0,2)*1), sDate.substr(2,2), sDate.substr(4,2))

    if (aqDateTime.Compare(dDate, aqDateTime.AddDays(aqDateTime.Today(),2)) === 0)

    sMessage = "Success"

    • wynandb1's avatar
      wynandb1
      Contributor

      Forgive me, but I dont have any programming skills. 

       

      I won't be able to do the set of sDate ? 

      • mtsmith's avatar
        mtsmith
        Contributor

        If I understand correctly, you will be able to do so.

         

        After this line;

        var sDate = myFile.ReadString(6);

         

         

        Insert these lines:
        var dDate = aqDateTime.SetDateElements(2000+(sDate.substr(0,2)*1), sDate.substr(2,2), sDate.substr(4,2))

        if (aqDateTime.Compare(dDate, aqDateTime.AddDays(aqDateTime.Today(),2)) === 0)
         Log.Message("The date in the file does equal today's date + 2 days.");
        else
         Log.Error("The date in the file does not equal today's date + 2 days.");