File Mover Blog

October 1, 2021

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

By Limagito-Team Pascal Script WIN , , Share:
SEARCH