#1 2023-08-31 15:27

adiosdonut
Member
Registered: 2021-11-09
Posts: 6

How to insert first 8 characters of containing folder name as prefix?

I don't know Pascal. Can anyone help me with a script? It should be pretty easy.

I want to rename files by adding the first 8 characters of the folder name in which the file exists to the beginning of the file name.

Examples (FolderName/FileName):

"Folder1_internal/File.docx"
will change to:
"Folder1_internal/Folder1_File.docx"

or

"F123456789/File.docx"
will change to:
"F123456789/F1234567File.docx"

Any help would be appreciated smile

Offline

#2 2023-08-31 17:51

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

Re: How to insert first 8 characters of containing folder name as prefix?

This script will prefix the filename with first 8 characters of the folder name:

var
  FolderName: WideString;
begin
  FolderName := WideExtractFileName(WideExtractFileDir(FilePath));
  FileName := Copy(FolderName, 1, 8) + FileName;
end.

Offline

#3 2023-08-31 19:13

adiosdonut
Member
Registered: 2021-11-09
Posts: 6

Re: How to insert first 8 characters of containing folder name as prefix?

Thank you!

Offline

Board footer

Powered by FluxBB