Forum Discussion

wynandb1's avatar
wynandb1
Contributor
10 years ago
Solved

Verify value in text file

Good day    I need to verify a specific value in a text file. It's a date value in YY/MM/DD format. It's in line 3 and starts at column 59 and ends at column 64.   From what I can see in the tuto...
  • cunderw's avatar
    10 years ago

     

    function ReadDateFromFile(){
      var sPath = "PATHTOFILE";
      
      // 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(NUMBEROFLINES); myFile.Skip(NUMBEROFCHARACTERS); var sDate = myFile.ReadString(10); // Closes the file myFile.Close(); }

    The above script should work to get just the date from the file, then you can set it to a variable and compare it like any other variable.

     

  • HKosova's avatar
    HKosova
    10 years ago

    Or use aqFileSystem.FindFiles to find a file by mask:

     

    var foundFiles = aqFileSystem.FindFiles("C:\\FolderName\\", "FileName_*_*");
    if (foundFiles != null) {
      if (foundFiles.Count == 1) {
        var sPath = foundFiles.Next().Path;
    Log.Message(sPath);

    // Read data from the file
    // ...
    } else { Log.Error("More that 1 file found."); } } else { Log.Error("File not found."); }