csv

  • 17 Apr

    How-To use a csv file as filter and destination path in LimagitoX File Mover

    Another example of how Pascal Script can be used. In this how-to we’ll explain you how the content of a csv file can be used to filter the source file and at the same time this csv file will be used to set the destination path.

    In this example we use C:\Test\Demo as base folder. It contains 3 subfolders which will be used by the Moving Rule.

    1. C:\Test\Demo\Csv  :  contains the Csv file which we will scan for its content. The content will give us the file filter and destination path.
    2. C:\Test\Demo\In  :  folder will be used as source of the moving rule
    3. C:\Test\Demo\Out  :  folder will be used as destination path. We’ll receive this info from the csv file.

    In the Csv subfolder we created an excel file. First column contains the filename filter. We’ll search for files which contain this string in its filename. The second column is used for the destination path when this file is found.

    Next we did an export of this excel file to csv. We need this cvs file for our Pascal Script.

    Content of the Source Folder:

    Select this folder in the Source Setup (WIN).

    Setup of the File Filter. Important, select RegEx Include filter and add %VSB as filter.

    Open the Pascal Script Setup:

     

    Add the following ‘On Rule Begin’ Pascal Script. Don’t forget to adjust the ctCsvFile constant (depends on your setup).

    Var
      iList: Integer;
      tmpList: TStringList;
      tmpEntry: String;
      tmpName: String;
      tmpCount: Integer;
      tmpPos: Integer;
    Const
      ctCsvFile = 'C:\Test\Demo\Csv\List.csv';
      ctCsvSep = ';';
    Begin
      psExitCode:= 0;
      psVSA := '';
      psVSB := '';
      // ... add your code here
      Try
        tmpList := TStringList.Create;
        Try
          tmpList.LoadFromFile(ctCsvFile);
          If tmpList.Count > 0 Then
          Begin
            tmpCount := tmpList.Count - 1;
            For iList := 0 to tmpCount Do
            Begin
              tmpEntry := Trim(tmpList.Strings[iList]);
              tmpPos := Pos(ctCsvSep, tmpEntry);
              If tmpPos <> 0 Then
              Begin
                tmpName := Copy(tmpEntry, 1, tmpPos-1);
                If iList = tmpCount Then
                  psVSB := psVSB + '.*' + tmpName + '.*'
                Else
                  psVSB := psVSB + '.*' + tmpName + '.*|'
              End;
            End;
            psVSA := tmpList.CommaText;
            // Debug Info
            psLogWrite(1, '', 'psVSA: ' + psVSA);
            psLogWrite(1, '', 'psVSB: ' + psVSB);
            // Set psExitCode
            If (psVSA <> '') And (psVSB <> '') Then
              psExitCode := 1;
          End;
        Except
          psLogWrite(1, '', 'Load Script File Exception');
        End;
      Finally
        tmpList.Free;
      End;
    End.

    Add the following ‘On Destination’ Pascal Script.

    Var
      iList: Integer;
      tmpList: TStringList;
      tmpEntry: String;
      tmpName: String;
      tmpPath: String;
      tmpCount: Integer;
      tmpPos: Integer;
    Const
      ctCsvSep = ';';
    Begin
      psExitCode:= 0;
      psVSC := '';
      // ... add your code here
      Try
        tmpList := TStringList.Create;
        Try
          tmpList.CommaText := psVSA;
          If tmpList.Count > 0 Then
          Begin
            tmpCount := tmpList.Count - 1;
            For iList := 0 to tmpCount Do
            Begin
              tmpEntry := Trim(tmpList.Strings[iList]);
              tmpPos := Pos(ctCsvSep, tmpEntry);
              If tmpPos <> 0 Then
              Begin
                tmpName := Copy(tmpEntry, 1, tmpPos-1);
                If Pos(tmpName, psFileName) <> 0 Then
                begin
                  tmpPath := Copy(tmpEntry, tmpPos+1, length(tmpEntry)-tmpPos);
                  If tmpPath <> '' Then
                  Begin
                    psVSC := tmpPath;
                    Break;
                  End;
                End;
              End;
            End;
            // Debug Info
            psLogWrite(1, '', 'psVSC: ' + psVSC);
            // Set psExitCode
            If (psVSC <> '') Then
              psExitCode := 1
            Else
              psLogWrite(1, '', 'Could not find a path for: ' + psFileName);
          End;
        Except
          psLogWrite(1, '', 'Find Destination Path Exception');
        End;
      Finally
        tmpList.Free;
      End;
    End.

    Add a WIN Destination:

    Set ‘Select Directory’ to %VSC

    Enable and trigger the rule. The Source files will be filtered and moved to the destination as set in the csv file.

    Destinations created with information from the csv file:

    Destination content example:

    This is just an example of what can be done using Pascal Script. If you need any help using Pascal Script, please let us know.

    Regards,

    Limagito Team

    By Limagito-Team Filters Pascal Script ,
  • 05 May

    XLS as Destination, Part 2

    Dear users,

    v2019.5.5.0

    If you missed the first parts: https://limagito.com/xls-as-destination/

    We’ve add the following new options to the XLS(X)/CSV as Destination option.

    Sheets, delete options:

    With this option you can select which sheets you want to delete using index or name of the sheet(s). Remember, the sheet index starts at 1.

    With the setup in the screenshot below we are going to delete the sheet with index 5 AND the sheet with name ‘SheetNameToDelete’.

    Colums, delete options:

    With this option you can select which columns you want to delete on a selected sheet. The selection of the sheet is possible using index or name of the sheet. Remember, column and sheet indexes start at 1.

    With the setup in the screenshot below we are going to delete column with index 2 on sheet with index 1.

    Rows, delete options:

    With this option you can select which rowss you want to delete on a selected sheet. The selection of the sheet is possible using index or name of the sheet. Remember, row and sheet indexes start at 1.

    With the setup in the screenshot below we are going to delete row with index 1 on sheet with index 1.

    Cell Values, rename options:

    With this option you can rename cell values in rows and colmuns on a selected sheet. The selection of the sheet is possible using index or name of the sheet. Remember, row , column and sheet indexes start at 1 (value = 0 = all rows/columns).

    With the setup in the screenshot below we are going to rename all columns of the first row on sheet with index 1. The text part ‘Before’ will be replaced by ‘After’ if the cell type is ‘Text’ (String).

    Please let us know if you have any question or need help with the setup

    Regards,

    Lilmagito Team,

    Pascal

    By Limagito-Team XLS/CSV ,
  • 28 Apr

    XLS as Destination

    Dear Users,

    Version v2019.4.27.0

    On user request we’ve added an option to convert xls files. At the moment the setup is only available from the Remote Setup tool (WebRemote will follow soon).

    The request we got was to convert xls(x) to csv (txt based) without Excel being installed but also other conversions are possible (xls tot xlsx, xlsx to xls, …).

    File Format possibilities:

    • Automatic, Automatically detect the type of the file when opening files.
    • Xls, Excel 97-2000-XP-2003
    • Text, Delimiter separated values. Depending on the delimiter, this can be csv, tab delimited text, etc.
    • Pxl, Pocket Excel 1.0 or 2.0
    • Xlsx, Excel 2007 standard file format. Note that this is *not* a macro enabled file format. If you want to save a file with macros, you need to use Xlsm instead.
    • Xlsm, Excel 2007 macro enabled file format.

    Sheet Name = Name of the sheet that needs to be converted

    Encoding = Encoding for the generated file, when writing a Text-delimited file (csv or txt). This parameter has no effect on xls/x files.

    • UTF8
    • UTF7
    • Unicode
    • Default
    • BigEndianUnicode
    • ASCII
    • ANSI

    Delimiter = Delimiter Char to use if Format Text ( #09 = Tab )

    Don’t forget to set the Filename filter to include the file types you want to convert.

    Further options like delete sheet(s), delete column(s),  renaming of cell values, .. are on our todo list.

    Regards,

    Limagito Team

    By Limagito-Team XLS/CSV ,
1 2 3 4
SEARCH