-
Notifications
You must be signed in to change notification settings - Fork 4
/
rmclipboard.pas
78 lines (64 loc) · 2.11 KB
/
rmclipboard.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
unit rmclipboard;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,ClipBrd;
procedure EraseFile(const FileName: string);
function GenerateRandomFilename: string;
function GetTemporaryPath: string;
function GetTemporaryPathAndFileName: string;
function GetTemporaryPathWithProvidedFileName(filename : string) : string;
procedure ReadFileAndCopyToClipboard(const FileName: string);
implementation
procedure EraseFile(const FileName: string);
begin
if FileExists(FileName) then
DeleteFile(FileName);
end;
function GenerateRandomFilename: string;
var
RandomString: string;
begin
// Generate a random string or number to use in the filename
RandomString := IntToHex(Random(MaxInt), 8); // Generate a random 8-character hexadecimal string
// Get the current timestamp as a string
Result := FormatDateTime('yyyymmdd_hhnnss', Now);
// Combine the timestamp and random string to create the random filename
Result := Result + '_' + RandomString + '.txt';
end;
function GetTemporaryPathAndFileName: string;
begin
// Get the temporary directory based on the operating system
Result := GetTempDir;
// Generate a unique file name within the temporary directory
Result := IncludeTrailingPathDelimiter(Result) + GenerateRandomFilename;
end;
function GetTemporaryPathWithProvidedFileName(filename : string) : string;
begin
// Get the temporary directory based on the operating system
Result := GetTempDir;
// Generate a unique file name within the temporary directory
Result := IncludeTrailingPathDelimiter(Result) + filename;
end;
function GetTemporaryPath: string;
begin
// Get the temporary directory based on the operating system
Result := GetTempDir;
end;
procedure ReadFileAndCopyToClipboard(const FileName: string);
var
FileContents: TStringList;
begin
// Create a TStringList to store the contents of the file
FileContents := TStringList.Create;
try
// Load the file contents into the TStringList
FileContents.LoadFromFile(FileName);
// Copy the contents to the clipboard
Clipboard.AsText := FileContents.Text;
finally
// Free the TStringList
FileContents.Free;
end;
end;
end.