#1 2023-10-24 05:07

SleepGlasses
Member
Registered: 2023-10-24
Posts: 3

Serialize files by parent folder name

Hello, this is my current code.

var
  i: Integer; ParentDir1, ParentDir2: WideString;
begin
  ParentDir1 := WideExtractFileDir(FilePath);
  ParentDir2 := WideExtractFileName(ParentDir1);
  i := i + 1;
  FileName := ParentDir2 + '-' + IntToStr(i);
end.

What I want to do is to completely modify the file name, and the rule is to add the parent folder name and sequence number.

This code can successfully name a single folder after dragging it in. But when I drag multiple folders, the sequence number will continue from the previous folder to the next, and the second folder does not start from 1. What should I do?


For example, the result I want is 1-1,1-2,1-3,2-1,2-2,2-3

But the result after running the above code is, 1-1, 1-2, 1-3, 2-4, 2-5, 2, 6

Also, after using this code, the extension disappeared. How can I keep it?

Last edited by SleepGlasses (2023-10-24 05:12)

Offline

#2 2023-10-24 10:32

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,400

Re: Serialize files by parent folder name

Can you provide a complete example with a list of original file paths and the desired new news?

The extension part is easy, you can append it at the end:

FileName := FileName + WideExtractFileExt(FilePath);

Offline

#3 2023-10-24 17:11

SleepGlasses
Member
Registered: 2023-10-24
Posts: 3

Re: Serialize files by parent folder name

Yes,
Before:

D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\1\1V3A3597.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\1\1V3A3598.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\1\1V3A3599.jpg
.....
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\29\1V3A3720.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\29\1V3A3721.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\29\1V3A3722.jpg


I want after:

D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\1\1-1.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\1\1-2.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\1\1-3.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\1\1-4.jpg
......
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\2\2-1.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\2\2-2.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\2\2-3.jpg
.......
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\3\3-1.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\3\3-2.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\3\3-3.jpg
.......
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\4\4-1.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\4\4-2.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\4\4-3.jpg
......
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\29\29-1.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\29\29-2.jpg
D:\文件\拍卖\9月\第三期第二场\第三期第二场细节图\29\29-3.jpg

The actual files are much more than here.

But now, that's all I can do.
mini_20231025002131.jpg

Last edited by SleepGlasses (2023-10-25 05:59)

Offline

#4 2023-10-25 08:54

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,400

Re: Serialize files by parent folder name

You can do this without the Pascal Script rule, with just these rules:

1) Insert: Insert ":File_FolderName:-" replacing current name (skip extension)
2) Serialize: Incremental from 1 repeat 1 step 1 (reset index if folder changes) as Suffix (skip extension)

renamer-reindex-by-folder.png

Offline

#5 2023-10-27 03:27

SleepGlasses
Member
Registered: 2023-10-24
Posts: 3

Re: Serialize files by parent folder name

den4b wrote:

You can do this without the Pascal Script rule, with just these rules:

1) Insert: Insert ":File_FolderName:-" replacing current name (skip extension)
2) Serialize: Incremental from 1 repeat 1 step 1 (reset index if folder changes) as Suffix (skip extension)

https://www.den4b.com/forum/img/members … folder.png



Thank you very much for your guidance, now I can use it smoothly! ! !:lol::lol::lol:
mini_22222.jpg

Offline

Board footer

Powered by FluxBB