You are not logged in.
Pages: 1
Here is a little PascalScript that I wrote that parses out the Directory and Parent Directory and renames the file to ParentDirectory---Directory---FileName. This is really handy when you use Windows search and have a bunch of 'same type' files in a bunch of different folders.
For example, suppose you have:
C:\dir_aa\dir_bb\dir_cc\myfile.txt
It would rename it to
dir_bb---dir_cc---myfile.txt
Then it is easy to apply the built in rules to remove/change the 3 delimited pieces of the filename.
By the way, double thumbs up to PascalScript. I've never used it before, but it is very powerful. **Thank you** so much for adding this feature to Renamer. Now it is possible to do almost renaming task!
var
Folder, Name, FName, FFName : String;
start, h0, h1, h2, h3 : Integer;
flag : Integer;
delim : String;
begin
delim := '---';
flag := 1;
Folder := WideExtractFileDir(FilePath);
start := 0;
while (flag = 1) do
begin
h0 := WidePosEx('\',Folder,start+1);
h1 := WidePosEx('\',Folder,h0+1);
h2 := WidePosEx('\',Folder,h1+1);
h3 := WidePosEx('\',Folder,h2+1);
start := h1;
if (h2 > 0) and (h3 = 0) then
begin
FFName := Copy(Folder, h1+1, h2-h1-1);
FName := Copy(Folder, h2+1, Length(Folder)-1);
flag := 0;
end;
end;
Name := WideExtractFileName(Folder);
FileName := FFName + delim + FName + delim + Name;
end.
Offline
I decided to give your script a try, but unfortunately it didn't work... Anyway, this operation could be done using a much simpler script! You will need latest development version: ReNamerBeta.zip. Script below will work on any layers of subfolders, inserting them in the new name, separating with a delimiter:
const
DELIM = '---';
var
I: Integer;
Folders: TStringsArray;
begin
Folders := WideSplitString(WideExtractFileDir(FilePath), '\');
for I:=Length(Folders)-1 downto 1 do
FileName := Folders[i] + DELIM + FileName;
end.
Enjoy
Offline
Did the files you were testing it on reside at least down 3 directories? I could see where that could make it fail. Moot point anyways, your script is MUCH nicer.
Thanks. I never object to improvements.
Offline
Yep, I might have tested with a wrong number of folders..
Offline
Pages: 1