Difference between revisions of "ReNamer:Scripts:Index files per folder"
Jump to navigation
Jump to search
(added navigation) |
(added SUFFIX parameter) |
||
Line 6: | Line 6: | ||
* INDEX_START - The first index to be used. | * INDEX_START - The first index to be used. | ||
* PAD_LENGTH - Length to which the index is padded with zeros. | * PAD_LENGTH - Length to which the index is padded with zeros. | ||
− | * | + | * INDEX_DELIMETER - Prefix for the index when inserting into the filename. |
+ | * SUFFIX - If TRUE, the index is appened to the end of the filename. If FALSE, index is prefixed. | ||
Below is the example of the results: | Below is the example of the results: | ||
Line 34: | Line 35: | ||
== Code == | == Code == | ||
− | Author: Denis Kozlov. Date: | + | Author: Denis Kozlov. Date: 18 August 2011. |
<source> | <source> | ||
Line 40: | Line 41: | ||
INDEX_START = 1; | INDEX_START = 1; | ||
PAD_LENGTH = 3; | PAD_LENGTH = 3; | ||
− | + | INDEX_DELIMETER = '_'; | |
− | + | SUFFIX = TRUE; | |
+ | |||
var | var | ||
Index: Integer; | Index: Integer; | ||
Initialized: Boolean; | Initialized: Boolean; | ||
Dir, LastDir: WideString; | Dir, LastDir: WideString; | ||
− | + | ||
function Pad(Number, NewLength: Integer): WideString; | function Pad(Number, NewLength: Integer): WideString; | ||
begin | begin | ||
Line 53: | Line 55: | ||
Result := '0' + Result; | Result := '0' + Result; | ||
end; | end; | ||
− | + | ||
begin | begin | ||
Dir := WideExtractFileDir(FilePath); | Dir := WideExtractFileDir(FilePath); | ||
Line 67: | Line 69: | ||
Inc(Index); | Inc(Index); | ||
end; | end; | ||
− | FileName := WideStripExtension(FileName) + | + | if SUFFIX then |
− | + | FileName := WideStripExtension(FileName) + | |
− | + | INDEX_DELIMETER + Pad(Index, PAD_LENGTH) + | |
+ | WideExtractFileExt(FileName) | ||
+ | else | ||
+ | FileName := WideExtractFilePath(FileName) + | ||
+ | Pad(Index, PAD_LENGTH) + INDEX_DELIMETER + | ||
+ | WideExtractFileName(FileName); | ||
end. | end. | ||
− | |||
</source> | </source> |
Revision as of 08:58, 18 August 2011
This script adds a serialization index to the end of every file on per folder basis. The index is incremented only when the folder path changes.
Below are the parameters of the script:
- INDEX_START - The first index to be used.
- PAD_LENGTH - Length to which the index is padded with zeros.
- INDEX_DELIMETER - Prefix for the index when inserting into the filename.
- SUFFIX - If TRUE, the index is appened to the end of the filename. If FALSE, index is prefixed.
Below is the example of the results:
Folder | Name | New Name |
---|---|---|
C:\TEMP\Folder A\ | A1.doc | A1_001.doc |
C:\TEMP\Folder A\ | A2.doc | A2_001.doc |
C:\TEMP\Folder A\ | A3.doc | A3_001.doc |
C:\TEMP\Folder B\ | B1.doc | B1_002.doc |
C:\TEMP\Folder C\ | C1.doc | C1_003.doc |
C:\TEMP\Folder C\ | C2.doc | C2_003.doc |
Note: You need to sort your files by Folder column so that all files from within the same folder appear together, because the index is changed every time the folder is changed in the list!
Tested
- ReNamer 5.50+ Beta
Code
Author: Denis Kozlov. Date: 18 August 2011.
const
INDEX_START = 1;
PAD_LENGTH = 3;
INDEX_DELIMETER = '_';
SUFFIX = TRUE;
var
Index: Integer;
Initialized: Boolean;
Dir, LastDir: WideString;
function Pad(Number, NewLength: Integer): WideString;
begin
Result := IntToStr(Number);
while Length(Result) < NewLength do
Result := '0' + Result;
end;
begin
Dir := WideExtractFileDir(FilePath);
if not Initialized then
begin
Initialized := True;
LastDir := Dir;
Index := INDEX_START;
end;
if not WideSameText(LastDir, Dir) then
begin
LastDir := Dir;
Inc(Index);
end;
if SUFFIX then
FileName := WideStripExtension(FileName) +
INDEX_DELIMETER + Pad(Index, PAD_LENGTH) +
WideExtractFileExt(FileName)
else
FileName := WideExtractFilePath(FileName) +
Pad(Index, PAD_LENGTH) + INDEX_DELIMETER +
WideExtractFileName(FileName);
end.