Skip to main navigation Skip to main content Skip to page footer
unit Util;

interface

uses
  Vcl.Graphics, System.Types, Winapi.Windows, SysUtils;

resourcestring
  StrMessagesFromEXIFTo = 'Messages from EXIFTool:';
  StrNoFilesFoundIn = ' not found or folder is empty.';
  StrFilesMoved = 'Files Moved:';
  StrFilesCopied = 'Files Copied:';

type
  TFileType = (ftUndefined, ftImage, ftRaw, ftVideo, ftWeb, ftRemove, ftOther, ftNone);
  TState = (stNone, stInit, stScan, stGetExif, stRestructure, stCompleting, stCompleted, stCancel);
  TFunctionResult = (frOk, frError, frCancel);
  TFileAction = (faMove, faCopy);

const
  StateStr: array[Low(TState)..High(TState)] of string = ('Idle.','Initializing...',
    'Scanning Source Directories...','Getting EXIF information...', 'File Restructuring...',
    'Completing...', 'Processing Files Completed.','');
  FileActionStr: array[Low(TFileAction)..High(TFileAction)] of string = ('Files Moved:', 'Files Copied:');

function TruncateFileName(const FileName: string; const MaxLength: Integer): string;

implementation

function TruncateFileName(const FileName: string; const MaxLength: Integer): string;
// Shorten the folder name so that it has Maxlength characters, keeping the file name intact
// regardless of whether Maxlength is exceeded
var
  Folder, AbbreviatedFolderName, Name: string;
begin
  if FileName.Length > MaxLength then
  begin
    Name:= ExtractFileName(FileName); // Preserve FileName, we do not want to alter it
    Folder := ExtractFileDir(FileName);
    AbbreviatedFolderName:= Copy(Folder, 1, MaxLength - Name.Length - 4) + '...\';
    Result := AbbreviatedFolderName + Name;
  end
  else Result:= FileName; // No modifications required
end;

end.