convert

  • 17 Jul

    Convert character set of text file

    Q: Convert character set of text file. I think I need some help here. We connect to a SFTP-server and download 3 files. One of these are a UTF-8 file named Vyymmdd.Thhmmss (i.e. V220627.TT110759). We need to download all 3 files, and convert the UTF-8 file to ISO-8859-1. I have found this article: https://limagito.com/text-character-encoding-conversion/

    And edited like this : psChangeTxtEncodingExt(psFilePath + psFileName, ctOutputpath + psFileName, 65001, 28591, True)

    Runtime Log says the file was successfully converted. But if I open the file in Notepad++ and click the “Encoding” option on the menu, it highlights UTF-8.

    A: In version v2022.7.17.0 we added some extra functions to help you convert the character set of  text files:

    Function psChangeTxtEncodingCk(Source, Destination: String; SrcCharset, DstCharset: String; WriteBOM: Boolean; ErrorAction: Integer): Boolean;

    Do not use this function when Source and Destination file are the same, use psChangeTxtEncodingCkExt instead.

    • ErrorAction: Controls how errors are handled. When a character in the input data cannot be converted to the target charset, the action taken is controlled by this property.
      The possible settings are:
      (0) drop the error characters,
      (1) substitute the data set by a ?
      (2) convert to a hex-escaped string (&#xXXXX)
      (3) RESERVED
      (4) RESERVED
      (5) RESERVED
      (6) RESERVED
      (7) Pass non-convertible characters to the output unchanged.
    • The Source and Destination Charset can be any of the supported encodings listed at Chilkat Supported Character Encodings.

    Function psChangeTxtEncodingCkExt(Source, Destination: String; SrcCharset, DstCharset: String; WriteBOM, WriteFileIfModified: Boolean): String;

      • WriteFileIfModified: writes the contents to a file, but only if it is a new file or if the contents are different than the existing file.
      • WriteBOM: the BOM (also known as a preamble), is emitted for charsets that define a BOM (such as utf-8, utf-16, utf-32, etc.)
      • The Source and Destination Charset can be any of the supported encodings listed at Chilkat Supported Character Encodings.

    #Filetransfer #Filemanagement #Encoding

    If you need any info about this ‘Convert character set’ question, please let us know.

    Best regards,

    Limagito Team

  • 20 Jan

    How-To Convert XLS Files using Pascal Script, Example 1

    https://limagito.com/converting-xls-files/

    First example: convert a xls(x) file to a tabbed txt file

    1) Add the following ‘Filename Include Filter’ so we are 100% sure we’ll only handle xls(x) files

    2) Add PS (Pascal Script) as Destination

    3) Add the following Pascal Script

    Const
      CsvPath = 'C:\Test\OUT_XLS\';
    Begin
      psExitCode := 0;
      // ... add your code here
      // 2 = Text based file, #09 is tab delimited, 0 is UTF8 text encoded
      If psConvertXlsFile(psFilePath + psFileName, CsvPath + ChangeFileExt(psFileName, '.txt'), 2, #09, 0, 'Run results') Then
      Begin
        psExitCode := 1;
        psLogWrite(1, '', 'Converted ' + psFilePath + psFileName);
      End
      Else
        psLogWrite(1, '', 'Convert error ' + psFilePath + psFileName);
     
      // psConvertXlsFile(psFilePath + psFileName, CsvPath + ChangeFileExt(psFileName, '.csv'), 2, ',', 0, 'Run results');
    End.
SEARCH