rename

  • 19 Nov

    How to rename a file to include day of the week

    How to rename a file to include day of the week

    Q: I found this in your blog but my filename pattern is different and I don’t know enough of the Pascal language to edit it.

    Here is an example of what I would like to rename.

    Original Filename: 2023-10-24_section_A2.pdf
    (2023-10-24 = October 24, 2023)
    Rename To:  Tues_2023-10-24_section_A2.pdf

    Any help you can provide would be greatly appreciated.

    A: Please have a look at the following example, I guess we need to fine-tune it. Let us know what you think.

    • We used a Windows folder as source:

    limagito file mover windows folder as source

    • Next, open our Pascal Script option:

    limagito file mover paascal script option

    • Enable and add the following ‘On Destination’ Pascal Script:

    You can download the script: here

    limagito file mover include day of the week pascal script

    • We used a Windows Folder as Destination:

    limagito file mover windows folder as destination

    •  Enable ‘Rename Files during Copy/Move’

    limagito file mover file renaming option

    • Renaming Setup:

    RegEx:   (.*)
    Replacement:   %VSA

    limagito file mover file renaming setup

    • RunTime Log Result:

    limagito file mover runtime log result

    #managedfiletransfer #filetransfer #filemanagement

    If you need any help with this ‘include day of the week’ request, please let us know.

    Best Regards,

    Limagito Team

  • 15 Sep

    How to rename a file keeping the last 7 characters intact

    How to rename a file keeping the last 7 characters intact

    Q: I need assistance to set up a move rule and rename the file to the destination. The file name needs to keep the last 7 characters intact before the file extension name. For example if the original file name is “Aspect Windows Pty Ltd_398x272_1531309.pdf” – we need it renamed to “1531309.pdf” before it is moved to the destination directory. Any idea how I can set this up please?

    A: This is possible using our Destination file renaming option

    Please enable and setup  ‘Rename Files during Copy/Move’ in your Destination setup:
    RegEx:  (.*)(.{7})\.(.*)
    Replacement:   \2.\3

    rename a file keeping

    Information about how to use regular expressions can be found here.

    If you need any info about this request, please let us know.

    #filetransfer #filemanagement

    Best regards,

    Limagito Team

    By Limagito-Team Rename ,
  • 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

SEARCH