Difference between revisions of "ReNamer:Scripts:Index files per folder"
Jump to navigation
Jump to search
(Created page with "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 ...") |
(added navigation) |
||
Line 1: | Line 1: | ||
+ | {{Up|ReNamer:Scripts}} | ||
+ | |||
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. | 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. | ||
Revision as of 12:59, 23 June 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.
- NUMBER_PREFIX - Prefix for the index when inserting into the filename.
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: 23 June 2011.
const
INDEX_START = 1;
PAD_LENGTH = 3;
NUMBER_PREFIX = '_';
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;
FileName := WideStripExtension(FileName) +
NUMBER_PREFIX + Pad(Index, PAD_LENGTH) +
WideExtractFileExt(FileName);
end.