#1 2011-08-16 15:51

crystal3d
Member
Registered: 2011-08-02
Posts: 7

Replace: meta tag "File_FolderName" with "sometext_FolderName"

Greetings,
I want to rename files that have same name as its folder only,

tried my luck with using a meta tag on the find panel instead of the replace panel:
f12.JPG

not suprisingly, it did not work...

if it did, i could rename 9000 models...

is it possible to get it done via pascal script or alike inside renamer?

Last edited by crystal3d (2011-08-16 15:51)

Offline

#2 2011-08-16 19:48

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Replace: meta tag "File_FolderName" with "sometext_FolderName"

I think this should be easy with PascalScript, but I found something unexpected.

One question for Denis: Shouldn't WideExtractFileDir() return the folder name instead of the folder path? for the folder path there's already WideExtractFilePath(), isn't it?.

Last edited by SafetyCar (2011-08-16 19:49)


If this software has helped you, consider getting your pro version. :)

Offline

#3 2011-08-16 20:57

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Replace: meta tag "File_FolderName" with "sometext_FolderName"

crystal3d wrote:

Greetings,
I want to rename files that have same name as its folder only,

is it possible to get it done via pascal script

FROM:
X:\Path\to\Test\Test.ext
X:\Path\to\Test\File.ext
TO:
X:\Path\to\Test\_Test.ext
X:\Path\to\Test\File.ext

Try:

var
  ParentFolder,FileBase: WideString;
begin
  ParentFolder := CalculateMetaTag(FilePath, ':File_FolderName:');
  FileBase := WideExtractBaseName(FileName);
  if (FileBase=ParentFolder) then
     FileName := '_' + FileName;
end.





If Parent and File have different case,

FROM:
X:\Path\to\Test\test.ext
TO:
X:\Path\to\Test\_test.ext

Try:

var
 ParentFolder,FileBase: WideString;
begin
  ParentFolder := CalculateMetaTag(FilePath, ':File_FolderName:');
  FileBase := WideExtractBaseName(FileName);
  ParentFolder := WideLowerCase(ParentFolder);
  FileBase := WideLowerCase(FileBase);
  if (FileBase=ParentFolder) then
     FileName := '_' + FileName;
end.




If Parent and File have different case,
but the file should get the same case as the parent folder

FROM:
X:\Path\to\Test\test.ext
TO:
X:\Path\to\Test\_Test.ext

Try something like:

var
 ParentFolder,FileBase: WideString;
begin
  ParentFolder := CalculateMetaTag(FilePath, ':File_FolderName:');
  FileBase := WideExtractBaseName(FileName);
  ParentFolder := WideLowerCase(ParentFolder);
  FileBase := WideLowerCase(FileBase);
  if (FileBase=ParentFolder) then
     FileName := '_' + CalculateMetaTag(FilePath, ':File_FolderName:');
end.

HTH?


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#4 2011-08-16 23:31

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

Re: Replace: meta tag "File_FolderName" with "sometext_FolderName"

Here is a good article which gives examples of how functions like ExtractFileDir behave:
http://www.delphibasics.co.uk/RTL.asp?N … actFileDir

I have also fixed the description of these functions on the Wiki:
ReNamer:Pascal_Script:Functions#File_Name_Utilities

To extract folder name of a file, you can use this snippet:

FileName := WideExtractFileName(WideExtractFileDir(FilePath));

Offline

#5 2011-08-17 08:19

crystal3d
Member
Registered: 2011-08-02
Posts: 7

Re: Replace: meta tag "File_FolderName" with "sometext_FolderName"

Bull's eye! DTH! smile

Offline

#6 2011-08-17 08:54

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Replace: meta tag "File_FolderName" with "sometext_FolderName"

crystal3d, thanks for the feedback!  (your long quoting will be removed later wink )


den4b wrote:

To extract folder name of a file, you can use this snippet:

FileName := WideExtractFileName(WideExtractFileDir(FilePath));

Thanks big_smile

Added to the wiki http://www.den4b.com/wiki/ReNamer:Pasca … :SplitPath
(re-formating allowed  tongue )


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

Board footer

Powered by FluxBB