Skip to main navigation Skip to main content Skip to page footer
pascal
 1unit Util;
 2
 3interface
 4
 5uses
 6  Vcl.Graphics, System.Types, Winapi.Windows, SysUtils;
 7
 8resourcestring
 9  StrMessagesFromEXIFTo = 'Messages from EXIFTool:';
10  StrNoFilesFoundIn = ' not found or folder is empty.';
11  StrFilesMoved = 'Files Moved:';
12  StrFilesCopied = 'Files Copied:';
13
14type
15  TFileType = (ftUndefined, ftImage, ftRaw, ftVideo, ftWeb, ftRemove, ftOther, ftNone);
16  TState = (stNone, stInit, stScan, stGetExif, stRestructure, stCompleting, stCompleted, stCancel);
17  TFunctionResult = (frOk, frError, frCancel);
18  TFileAction = (faMove, faCopy);
19
20const
21  StateStr: array[Low(TState)..High(TState)] of string = ('Idle.','Initializing...',
22    'Scanning Source Directories...','Getting EXIF information...', 'File Restructuring...',
23    'Completing...', 'Processing Files Completed.','');
24  FileActionStr: array[Low(TFileAction)..High(TFileAction)] of string = ('Files Moved:', 'Files Copied:');
25
26function TruncateFileName(const FileName: string; const MaxLength: Integer): string;
27
28implementation
29
30function TruncateFileName(const FileName: string; const MaxLength: Integer): string;
31// Shorten the folder name so that it has Maxlength characters, keeping the file name intact
32// regardless of whether Maxlength is exceeded
33var
34  Folder, AbbreviatedFolderName, Name: string;
35begin
36  if FileName.Length > MaxLength then
37  begin
38    Name:= ExtractFileName(FileName); // Preserve FileName, we do not want to alter it
39    Folder := ExtractFileDir(FileName);
40    AbbreviatedFolderName:= Copy(Folder, 1, MaxLength - Name.Length - 4) + '...\';
41    Result := AbbreviatedFolderName + Name;
42  end
43  else Result:= FileName; // No modifications required
44end;
45
46end.
47
48