Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: ArrayFileGetCSV Error 1808 File Invalid CSV line Bad Format Formatting @LF Validate CSV
;----------------------------------------------------------------------------------------------------------------------------------------- #DefineFunction udfCheckCSVFile (strCSVFile, strDelimiter, blnTrim) ; Trim leading and trailing empty lines. If !!blnTrim intBytesWritten = FilePut (strCSVFile, StrReplace (StrTrim (StrReplace (FileGet (strCSVFile), @CRLF, @TAB)), @TAB, @CRLF)) EndIf blnRetVal = @TRUE strFileTemp = FileCreateTemp ("WBT") arrCSVFile = ArrayFileGet (strCSVFile) intLines = ArrInfo (arrCSVFile, 1) intLineLast = intLines - 1 IntControl (72, 1, @TRUE, "", 0) ; On next cancel event goto label :CANCEL. For intLine = 0 To intLineLast intBytesWritten = FilePut (strFileTemp, arrCsvFile[intLine]) intLastEM = ErrorMode (@OFF) LastError () arrTest = ArrayFileGetCSV (strFileTemp, 0, strDelimiter) intLastError = LastError () ErrorMode (intLastEM) If intLastError > 0 blnRetVal = @FALSE Pause ("Error in CSV line", "Line: " : intLine + 1 : @LF : arrCsvFile[intLine]) EndIf Next :CANCEL Drop (arrTest, arrCSVFile) blnresult = FileDelete (strFileTemp) Return blnRetVal ;.......................................................................................................................................... ; This UDF udfCheckCSVFile is a simple helper to check a given CSV file for possible formatting errors. ; ; The given CSV File must ; - have CRLF end of line delimiters; ; - not have any @TAB character; ; - allow read and write access when trimming leading and trailing empty lines. ; ; This UDF returns a boolean value @TRUE (1) or @FALSE (0) to indicate that the given file can be used as a CSV file or not. ; ; Detlev Dalitz.20100814. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------
Article ID: W17655Filename: ArrayFileGetCsv - How to detect invalid CSV line.txtFile Created: 2014:04:18:08:41:08Last Updated: 2014:04:18:08:41:08