wynandb1
10 years agoContributor
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 tutorials you can only compare files byte for byte . I want to verify if the date in the file , in line 3 between , column 59 and 64 is current date + 2 days. So the date in the file must be two days from today's date . I need to verify this specifically.
Can someone perhaps help ?
Thank you
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.
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."); }