#1 2011-04-20 16:03

schmidty
Member
Registered: 2011-04-20
Posts: 2

Keep only first letter of each word

Hi everyone,

I have searched to see if my question has been answered, but no luck.  What I would like to do is rename files and keep only the first letter of each word. Example:

"middle arc inside stiffener plate - flat pattern.dxf"  would become "maisp-fp.dxf".  I assume this can be done with a script, (?!?) but I have no idea how to do it.  The spaces being removed isn't so important.  That much I can manage on my own! tongue

Thank you for any help you can give me!

By the way...what a great program!  I can't begin to add up all the time it has saved me!  Thanks den4b!!!!!!

Offline

#2 2011-04-20 20:18

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

Re: Keep only first letter of each word

Hi schmidty, welcome!

FROM:
"middle arc inside stiffener plate - flat pattern.dxf"
TO:
"maisp-fp.dxf".
DO:
Use an PascalScript (Wiki: HowTo use an PascalScript)

//get the first letter of all words and remove the rest, remove spaces too
//stefan

var
  Words : TStringsArray;
  FirstChars : WideString;
  i : Integer;
  
begin
  //init, emtpy the var
  FirstChars:='';
  
  //split the FileName into words at spaces
  Words:=WideSplitString(WideExtractBaseName(FileName), ' ');
  
  //for each word in words do: get first char
  for i:=0 to Length(Words) - 1 do
      FirstChars := FirstChars + WideCopy(Words[i], 1, 1);

  //Compose the new FileName
  FileName := FirstChars + WideExtractFileExt(FileName);
end.


Always test with copies of your files first.


HTH? big_smile


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

#3 2011-04-21 04:17

schmidty
Member
Registered: 2011-04-20
Posts: 2

Re: Keep only first letter of each word

Stefan,

Ich danke Ihnen sehr viel! big_smile  That script worked great!

I will read the "how-to" Wiki page you linked me to as well.  Since I know exactly what your script does, I can use that as a learning tool to help me learn Pascal.

Thanks again!

Offline

#4 2011-04-21 17:09

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

Re: Keep only first letter of each word

There is an alternative way for doing this, using RegEx rule:

1) RegEx: Replace expression "(\w)\w*" with "$1" (skip extension)
2) Replace: Replace all " " with "" (skip extension)

This will also convert "middle arc inside stiffener plate - flat pattern.dxf" into "maisp-fp.dxf".

Script is of course a lot more flexible and highly customizable!

Offline

Board footer

Powered by FluxBB