filename

  • 01 Oct

    Immediate folder name as filename in Limagito File Mover

    Q: I am trying to append a folder name to a file name but having a little trouble. The file is under 1 or 2 subfolder. After the file move I would like to append the very last folder name to the file name , and I don’t want to copy the source folder structure. Can you help me.

    Limagito File Mover Subfolder Filename

    A: Yes this is possible using some Pascal Script. We’ll need two destinations.

    • The first destination must be our ‘Pascal Script’. This script will strip the immediate subfolder from the complete subfolder part.
    • The second destination will be a Windows folder (WIN). In this destination we’ll rename the file using the info from the first destination (pascal script).

    Limagito File Mover Destination Setup

    Let’s start with the first destination (Pascal Script):

    Var
      iList: Integer;
      tmpEntry: String;
      tmpList: TStringList;
    Begin
      psExitCode:= 1;
      // ... add your code here
      psVSA := Trim(psStringReplace(psFilePath, psSourcePath, ''));
      If psVSA <> '' Then
      Begin
        tmpList := TStringList.Create;
        Try
          tmpList.Delimiter := '\';
          tmpList.DelimitedText := psVSA;
          psVSA := '';
          // Iterate
          For iList := (tmpList.Count - 1) DownTo 0 Do
          Begin
            tmpEntry := Trim(tmpList.Strings[iList]);
            If tmpEntry <> '' Then
            Begin
              psVSA := tmpEntry;
              Break;
            End;
          End;
        Finally
          tmpList.Free;
        End;
      End;
      // Adjust
      If psVSA <> '' Then
        psVSA := psVSA + '_';
      // Debug
      psLogWrite(1, '', 'Stripped SubFolder: ' + psVSA);
    End.

    Limagito File Mover Pascal Script Setup

    Next we’ll setup our second destination (WIN):

    Limagito File Mover WIN as Destination

    Don’t forget to disable the ‘Create SubDir’ option if you don’t want to copy the source folder structure.

    Limgito File Mover Create Subfolder option

    File renaming setup:

    Limagito File Mover File Rename

    RegEx: (.*)

    Replacement: %VSA\1

    Limagito File Mover File Rename Setup

    RunTime Log:

    Limagito File Mover RunTime Log

    #FileTransfer

    If you need any info about this ‘Immediate folder name as filename’ question, please let us know.

    Best regards,

    Limagito Team

  • 15 Jul

    Can you use the date in a file name to create the subdirectory?

    Q: Can you use the date in a file name to create the subdirectory? So, when moving the attached file, we would like to create a sub-directory of:

    C:\Users\niall\WindowsDatabase\Destination\Valuation\2021\06. Jun\ ,

    Where ‘2021\06. Jun\’ is derived from the name of the source file? Thinking if we can pull a date variable/parameter from the filename we could pass it into the directory set-up. I can’t see how to get there.

    A: Yes this is possible using some Pascal Script.

    We received the following filename from the customer: ‘Valuation_2021-06-21.csv’. We’ll use this in the following example but remember we can adjust the script for any other filename you might have.

    1.Using a Windows folder as Source:

    Limagito File Mover Windows Folder as Source

    2.Open our ‘Pascal Script’ option:

    Limagito File Mover Pascal Script Menu

    3. Add  and enable the following ‘On Destination’ Pascal Script:

     

    Var
      tmpDate: TDateTime;
      tmpDatePart: String;
      tmpList: TStringList;
     
    Function GetDateFromString(const aInput: String): TDateTime;
    var
      wYear, wMonth, wDay: Word;
    Begin
      wYear := StrToInt(Copy(aInput, 1, 4));
      wMonth := StrToInt(Copy(aInput, 6, 2));
      wDay := StrToInt(Copy(aInput, 9, 2));
      Try
        Result := EncodeDate(wYear, wMonth, wDay);
      Except
        Result := 0;
      End;
    End;
     
    Begin
      // Valuation_2021-06-21.csv
      psExitCode:= 0;
      // ... add your code here
      tmpList := TStringList.create;
      Try
        tmpList.delimiter := '_';
        tmpList.DelimitedText := psFileName;
        If tmpList.Count >= 2 Then
        Begin
          tmpDatePart := tmpList.Strings[1];
          psLogWrite(1, '', 'DatePart from File ' + psFilePath + psFileName + ': ' + tmpDatePart);
          tmpDate := GetDateFromString(tmpDatePart);
          // 2021\06. Jun\
          If Not (tmpDate = 0) Then
          Begin
            psVSA := FormatDateTime('YYYY', tmpDate);
            psVSA := psVSA + '\' + FormatDateTime('DD', tmpDate);
            psVSA := psVSA + '. ' + FormatDateTime('MMM', tmpDate) + '\';
            // Debug        
            psLogWrite(1, '', 'Result psVSA: ' + psVSA);
            psExitCode := 1;
          End
          Else
            psLogWrite(1, '', 'GetDateFromString Error, ' + tmpDatePart);
        End
        Else
          psLogWrite(1, '', 'Count FileName _ Parts Error, ' + psFileName);
      Finally
        tmpList.free;
      End;
    End.

    Limagito File Mover Pascal Script

    4. Adjust the ‘Create Subdir option’ to %VSA in your Destination Setup. We used a Windows folder as Destination in our example.

    Limagito File Mover Destination Setup

    5. RunTime Log Result:

    Limagito File Mover RunTime Log

    #FileTransfer

    If you need any info about this ‘date in a file name to create the subdirectory’ feature, please let us know.

    Best regards,

    Limagito Team

  • 12 Jul

    Adjust datepart of a filename with Limagito File Mover

    Q: Adjust datepart of a filename with Limagito File Mover. I have a file name “thisfile_20210712” and after transfer I would like to reduce one day “thisfile_20210711”. I can try to figure out with regex but what if the day is 20210801” that would be challenge for regex . I don’t know if you have any thing to allow external window host script to run after the job to fix this.

    A: Yes this is possible using some Pascal Script. If you think this is too difficult for you, just contact us and we’ll help.

    We received an example file of the customer:

    This is the example  “thisfile_20210711_new.pdf”

    Expected:  “thisfile_20210710_revised.pdf”

    1.Our Source is a Windows Folder.

    Limagito File Mover Windows Folder as Source

    2. Add the following ‘OnDestination’ Pascal Script. This script will strip and adjust the datepart in the filename.

    Limagito File Mover Pascal Script Menu

    Limagito File Mover On Destination Pascal Script

    Var
      iList: Integer;
      tmpDate: TDateTime;
      tmpDatePart: String;
      tmpList: TStringList;
     
    Function GetDateFromString(const aInput: String): TDateTime;
    var
      wYear, wMonth, wDay: Word;
    Begin
      wYear := StrToInt(Copy(aInput, 1, 4));
      wMonth := StrToInt(Copy(aInput, 5, 2));
      wDay := StrToInt(Copy(aInput, 7, 2));
      Try
        Result := EncodeDate(wYear, wMonth, wDay);
      Except
        Result := 0;
      End;  
    End;  
     
    Begin
      // thisfile_20210711_new.pdf
      psExitCode:= 0;
      // ... add your code here
      tmpList := TStringList.create;
      Try
        tmpList.delimiter := '_';
        tmpList.DelimitedText := psFileName;
        If tmpList.Count >= 3 Then     
        Begin
          tmpDatePart := tmpList.Strings[1];
          psLogWrite(1, '', 'DatePart from File ' + psFilePath + psFileName + ': ' + tmpDatePart);     
          tmpDate := GetDateFromString(tmpDatePart);
          tmpDate := psIncDay(tmpDate, -1);
          //
          If Not (tmpDate = 0) Then
          Begin
            tmpList.Strings[1] := FormatDateTime('YYYYMMDD', tmpDate);
            // Iterate
            For iList := 0 to (tmpList.Count-1) Do
            Begin
              If iList = 0 Then
                psVSA := tmpList.Strings[iList]
              Else  
                psVSA := psVSA + '_' + tmpList.Strings[iList];        
            End;  
            psLogWrite(1, '', 'Reesult psVSA: ' + psVSA);        
            psExitCode := 1;
          End
          Else          
            psLogWrite(1, '', 'GetDateFromString Error, ' + tmpDatePart);
        End
        Else
          psLogWrite(1, '', 'Count FileName _ Parts Error, ' + psFileName);        
      Finally
        tmpList.free;
      End;  
    End.

    3. In your Destination setup we’ll use the File Renaming option to rename the originale filename to:

    • the adjusted filename (%VSA)
    • ‘new.pdf’ part to ‘revised.pdf’

    Limagito File Mover File Renaming

    Limagito File Mover File Renaming

    4. RunTime Log Result:

    Limagito File Mover RunTime Log Result

    #FileTransfer

    If you need any info about this new ‘Adjust datepart of a filename’ option, please let us know.

    Best regards,

    Limagito Team

1 2
SEARCH