小工具整理
This commit is contained in:
commit
1011eb44e1
566 files changed
+267142
No files matched your search
@@ -0,0 +1,9 @@
|
||||
var
|
||||
DateTime: TDateTime;
|
||||
|
||||
begin
|
||||
DateTime := FileTimeModified(FilePath);
|
||||
FileName := WideExtractBaseName(FileName) +
|
||||
FormatDateTime(' (dd-mmm-yyyy)', DateTime) +
|
||||
WideExtractFileExt(FileName);
|
||||
end.
|
||||
@@ -0,0 +1,55 @@
|
||||
{ XOR-BASE64 Encrypt Filename against a String Key }
|
||||
|
||||
const
|
||||
KEY = 'My Secret Key'; // Set your key!
|
||||
DECODE = False; // "True" or "False"
|
||||
|
||||
function XorEnDeCrypt(const S: String): String;
|
||||
var
|
||||
I, IK, Code: Integer;
|
||||
begin
|
||||
IK := 1;
|
||||
Result := '';
|
||||
for I := 1 to Length(S) do
|
||||
begin
|
||||
if IK > Length(KEY) then IK := 1;
|
||||
Code := (Ord(S[I]) xor Ord(KEY[IK]));
|
||||
Result := Result + Chr(Code);
|
||||
IK := IK + 1;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure ReplaceChar(var S: String; Find, Replace: Char);
|
||||
var
|
||||
I: Integer;
|
||||
begin
|
||||
for I:=1 to Length(S) do
|
||||
if S[I] = Find then
|
||||
S[I] := Replace;
|
||||
end;
|
||||
|
||||
function Encrypt(const S: WideString): String;
|
||||
begin
|
||||
Result := UTF8Encode(S);
|
||||
Result := XorEnDeCrypt(Result);
|
||||
Result := Base64Encode(Result);
|
||||
ReplaceChar(Result, '/', '=');
|
||||
end;
|
||||
|
||||
function Decrypt(const S: String): WideString;
|
||||
var
|
||||
Temp: String;
|
||||
begin
|
||||
Temp := S;
|
||||
ReplaceChar(Temp, '=', '/');
|
||||
Temp := Base64Decode(Temp);
|
||||
Temp := XorEnDeCrypt(Temp);
|
||||
Result := UTF8Decode(Temp);
|
||||
end;
|
||||
|
||||
begin
|
||||
if DECODE then
|
||||
FileName := Decrypt(FileName)
|
||||
else
|
||||
FileName := Encrypt(FileName);
|
||||
end.
|
||||
@@ -0,0 +1,7 @@
|
||||
// This file is used for demonstrating the use of {$INCLUDE} directive.
|
||||
|
||||
function ExampleFunction: String;
|
||||
begin
|
||||
// Generate a random number seqeunce.
|
||||
Result := IntToStr(RandomRange(1000, 9999));
|
||||
end;
|
||||
@@ -0,0 +1,49 @@
|
||||
// This script reads dates from filenames in format: yyyy-mm-dd hh-nn-ss.JPG
|
||||
// then adds/subtracts N hours from the date and prints the new date in the
|
||||
// format defined by DateOutputFormat variable. HoursSpan variable defines
|
||||
// how many hours should be added/subtracted (use minus for subtraction).
|
||||
|
||||
const
|
||||
HoursSpan = -3; // amount of hours to add or subtract!!
|
||||
DateOutputFormat = 'yyyy-mm-dd hh.nn.ss'; // output date format!!
|
||||
HoursPerDay = 24; // do not change this!!
|
||||
|
||||
var
|
||||
iYear, iMonth, iDay, iHour, iMin, iSec: Integer;
|
||||
Date, Time, DateTime: TDateTime;
|
||||
|
||||
procedure AddHours(var ADateTime: TDateTime; const ANumberOfHours: Integer);
|
||||
begin
|
||||
ADateTime := ((ADateTime * HoursPerDay) + ANumberOfHours) / HoursPerDay;
|
||||
end;
|
||||
|
||||
begin
|
||||
// extract date-time variables as integers
|
||||
iYear := StrToIntDef(Copy(FileName, 1, 4), -1);
|
||||
iMonth := StrToIntDef(Copy(FileName, 6, 2), -1);
|
||||
iDay := StrToIntDef(Copy(FileName, 9, 2), -1);
|
||||
iHour := StrToIntDef(Copy(FileName, 12, 2), -1);
|
||||
iMin := StrToIntDef(Copy(FileName, 15, 2), -1);
|
||||
iSec := StrToIntDef(Copy(FileName, 18, 2), -1);
|
||||
|
||||
// process only if all variables are correctly converted
|
||||
if (iYear >= 0) and (iMonth >= 0) and (iDay >= 0) and
|
||||
(iHour >= 0) and (iMin >= 0) and (iSec >= 0) then
|
||||
|
||||
begin
|
||||
// create a new date-time variable
|
||||
Date := EncodeDate(iYear, iMonth, iDay);
|
||||
Time := EncodeTime(iHour, iMin, iSec, 0);
|
||||
DateTime := Date + Time;
|
||||
|
||||
// add hours (use minus for subtracting)
|
||||
AddHours(DateTime, HoursSpan);
|
||||
|
||||
// concatenate the rest of the filename and the new date
|
||||
FileName := Copy(FileName, 20, Length(FileName));
|
||||
FileName := FormatDateTime(DateOutputFormat, DateTime) + FileName;
|
||||
end
|
||||
|
||||
// something went wrong
|
||||
else FileName := 'INVALID INPUT';
|
||||
end.
|
||||
@@ -0,0 +1,10 @@
|
||||
function GetTickCount: Longint;
|
||||
external 'GetTickCount@kernel32.dll stdcall';
|
||||
|
||||
procedure Sleep(Milliseconds: Cardinal);
|
||||
external 'Sleep@kernel32.dll stdcall';
|
||||
|
||||
begin
|
||||
FileName := IntToStr(GetTickCount);
|
||||
Sleep(10);
|
||||
end.
|
||||
@@ -0,0 +1,7 @@
|
||||
var
|
||||
I: Integer;
|
||||
|
||||
begin
|
||||
I := I + 1;
|
||||
FileName := IntToStr(I);
|
||||
end.
|
||||
@@ -0,0 +1,16 @@
|
||||
// Boolean variables are set to False when
|
||||
// they are compiled, so we can think of that
|
||||
// fact as of the code not been Initialized.
|
||||
var
|
||||
Initialized: Boolean;
|
||||
|
||||
procedure Initialize;
|
||||
begin
|
||||
Initialized := True;
|
||||
// Initialization code here
|
||||
end;
|
||||
|
||||
begin
|
||||
if not Initialized then Initialize;
|
||||
// The main renaming code here
|
||||
end.
|
||||
@@ -0,0 +1,7 @@
|
||||
var
|
||||
I: Integer;
|
||||
|
||||
begin
|
||||
I := I + 1;
|
||||
FileName := FileReadLine('C:\Names.txt', I);
|
||||
end.
|
||||
@@ -0,0 +1,17 @@
|
||||
{ This script moves a portion of a filename }
|
||||
|
||||
const
|
||||
MOVE_START = 5; // beginning of the movable portion
|
||||
MOVE_LENGTH = 3; // length of the movable portion
|
||||
MOVE_TO = 3; // new position for the portion
|
||||
|
||||
var
|
||||
BaseName, Portion: WideString;
|
||||
|
||||
begin
|
||||
BaseName := WideExtractBaseName(FileName);
|
||||
Portion := WideCopy(BaseName, MOVE_START, MOVE_LENGTH);
|
||||
WideDelete(BaseName, MOVE_START, MOVE_LENGTH);
|
||||
WideInsert(Portion, BaseName, MOVE_TO);
|
||||
FileName := BaseName + WideExtractFileExt(FileName);
|
||||
end.
|
||||
@@ -0,0 +1,44 @@
|
||||
const
|
||||
PAD_TO_LENGTH = 3;
|
||||
|
||||
function CountDigits(const S: WideString; StartI: Integer): Integer;
|
||||
var I: Integer;
|
||||
begin
|
||||
Result := 0;
|
||||
for I:=StartI to WideLength(S) do
|
||||
begin
|
||||
if IsWideCharDigit(S[I]) then
|
||||
Inc(Result)
|
||||
else
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
|
||||
function MakeZeros(Count: Integer): WideString;
|
||||
var I: Integer;
|
||||
begin
|
||||
Result := '';
|
||||
for I:=1 to Count do
|
||||
Result := Result + '0';
|
||||
end;
|
||||
|
||||
var
|
||||
Start, Count: Integer;
|
||||
|
||||
begin
|
||||
Start := 1;
|
||||
while Start < WideLength(FileName) do
|
||||
begin
|
||||
Count := CountDigits(FileName, Start);
|
||||
if (Count > 0) then
|
||||
if (Count < PAD_TO_LENGTH) then
|
||||
begin
|
||||
WideInsert(MakeZeros(PAD_TO_LENGTH-Count), FileName, Start);
|
||||
Start := Start + PAD_TO_LENGTH;
|
||||
end
|
||||
else
|
||||
Start := Start + Count
|
||||
else
|
||||
Inc(Start);
|
||||
end;
|
||||
end.
|
||||
@@ -0,0 +1,36 @@
|
||||
var
|
||||
Files: TWideStringArray;
|
||||
|
||||
procedure Add(const S: WideString);
|
||||
begin
|
||||
SetLength(Files, Length(Files)+1);
|
||||
Files[Length(Files)-1] := S;
|
||||
end;
|
||||
|
||||
function Exists(const S: WideString): Boolean;
|
||||
var I: Integer;
|
||||
begin
|
||||
Result := False;
|
||||
for I:=0 to Length(Files)-1 do
|
||||
if WideSameText(Files[I], S) then
|
||||
begin Result := True; Break; end;
|
||||
end;
|
||||
|
||||
var
|
||||
NewFileName: WideString;
|
||||
Counter: Integer;
|
||||
|
||||
begin
|
||||
Counter := 2;
|
||||
NewFileName := FileName;
|
||||
while Exists(NewFileName) do
|
||||
begin
|
||||
NewFileName :=
|
||||
WideExtractBaseName(FileName) +
|
||||
' (' + IntToStr(Counter)+')' +
|
||||
WideExtractFileExt(FileName);
|
||||
Counter := Counter + 1;
|
||||
end;
|
||||
FileName := NewFileName;
|
||||
Add(FileName);
|
||||
end.
|
||||
@@ -0,0 +1,8 @@
|
||||
// The include directive loads code from an external file,
|
||||
// allowing reuse and better organization of your code.
|
||||
{$INCLUDE 'Example include file.inc'}
|
||||
|
||||
begin
|
||||
// Use a function contained in the included file.
|
||||
FileName := ExampleFunction;
|
||||
end.
|
||||
@@ -0,0 +1,21 @@
|
||||
procedure DoSomething(var Parameter: WideString);
|
||||
begin
|
||||
// Do something here with Parameter.
|
||||
// Original passed variable will be changed,
|
||||
// because Parameter has been passed as a Var.
|
||||
end;
|
||||
|
||||
function DoAnother(Parameter: WideString): WideString;
|
||||
begin
|
||||
// Do something here with Parameter,
|
||||
// and return Result as a string.
|
||||
Result := '';
|
||||
end;
|
||||
|
||||
var
|
||||
S: WideString;
|
||||
|
||||
begin
|
||||
DoSomething(S);
|
||||
FileName := DoAnother(S);
|
||||
end.
|
||||
Reference in new issue
Block a user