#1 2007-12-01 13:59

eagle1
Member
Registered: 2007-12-01
Posts: 1

Is there a way to truncate file names?

Hello - looked around, couldn't really find an answer to this. Is there a way to scan a folder and its sub-folders and all contents to examine file names and allow the specification that a filename should not be able to exceed a specified length? I would like to limit file names (without affecting file extensions) to around 100 characters or so - especially useful when copying between different hard drive formats, OS's, or when burning specific types of CD or DVD data discs. Thanks for any hints! (I looked around for a PascalScript manual online this morning but couldn't find one.)

Offline

#2 2007-12-01 19:46

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

Re: Is there a way to truncate file names?

Hi eagle, welcome.

Doing it this way you wrote could mess up the file names because you could cut/loose important information from the file name.
Like for stored websides and there content-folder.

Better would be to think about an algorithm for an pascal script like to shrink single words to an abbreviation, delete blanks or like this...
Something like:

1. Shorten the filename:  deleting unnecessary spaces
   2. Destruct the filename "Remix" => "Rmx" etc.
   3. Delete space between letters and make letters uppercase: "Michael Jackson-Beat it.mp3" => "MichaelJackson-BeatIt.mp3"
   4. Delete Vowels "Stevie Wonder - Happy birthday" => "Stv Wndr - Hppy brthdy"
   5. Delete double letters: "Madonna" =>"Madona"

----------------------------------------------------------------


Any way, here is an solution to your request:

> to scan a folder and its sub-folders
1. Use FILTERS and check "Include sub folders"
2. use the button ADD FOLDERS to add folders

> I would like to limit file names  to around 100 characters
1. Add an RULE
2. choose DELETE
3. set FROM position [ 101 ]
4. set UNTIL the end


> (without affecting file extensions)
1. check "SKIP EXTENSION"


Since this could let to duplicate file names
1. you should add as next an other RULE
2. choose PascalScript
3. load the script "Serialize duplicates" with the [Scripts]-button


HTH?
Stefan


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 2007-12-01 23:07

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

Re: Is there a way to truncate file names?

1. Shorten the filename:  deleting unnecessary spaces
   2. Destruct the filename "Remix" => "Rmx" etc.
   3. Delete space between letters and make letters uppercase: "Michael Jackson-Beat it.mp3" => "MichaelJackson-BeatIt.mp3"
   4. Delete Vowels "Stevie Wonder - Happy birthday" => "Stv Wndr - Hppy brthdy"
   5. Delete double letters: "Madonna" =>"Madona"

I have tried to wrote such an script.

Note: i am NOT an programmer! So this script may be buggy roll

I think this can't match all of your problems, but it's an start. . . . . . Please test it first with duplicates of your files!!! or create a backup.


// Truncate file names.pas
// To shorten long file name with some tricks found by Ofa.
// Nov. 2007 by Stefan

const
  NewNameLenght = 60; // how long should the 'New Name' be? Choose between 1 and 100 only. This line has f.ex. 120 chars.

var
  OldName : WideString;
  OldExt : WideString;
  NewName, Beginning, Ending : WideString;
  Count : Integer;
  
begin
//Show an message only once:
If count < 1 Then
ShowMessage('To handle duplicate name please load the "Serialize duplicates" script after this script too')
Count := 1

  OldName := WideExtractBaseName(FileName)   //store the original file name, perhaps we need them?
  OldExt  := WideExtractFileExt(FileName)    //store the extension of the file name
  NewName := OldName
  


  // clean up the NewName
  // ( 2. Destruct the filename "Remix" => "Rmx" etc.)
  // ReplaceRegEx(const Input, Find, Replace: WideString; const CaseSensitive, UseSubstitution: Boolean): WideString;
     NewName := ReplaceRegEx(NewName,'Feat.*?\b','ft',False,False);
     NewName := ReplaceRegEx(NewName,'Remix.*?\b','RMX',False,False);
     //... here your substitutes



  // find two identical chars in filename and delete one of them: 
  //(5. Delete double letters: "Madonna" =>"Madona")
     NewName := ReplaceRegEx(NewName, '(.)\1', '$1', False, True);



  // case: every first char upper case (because we going to delete the spaces between words)
  // (3. Delete space between letters and make letters uppercase: "Michael Jackson-Beat it.mp3" => "MichaelJackson-BeatIt.mp3")
  // WideCaseCapitalize(const S: WideString): WideString;
     NewName := WideCaseCapitalize(NewName);



  // delete blanks/spaces
  // WideReplaceStr(const S, OldPattern, NewPattern: WideString): WideString;
     NewName := WideReplaceStr(NewName, ' ', '');



  // Delete vowels
  // (4. Delete Vowels "Stevie Wonder - Happy birthday" => "Stv Wndr - Hppy brthdy")
     // Leave the vowels for the first few (here 20) chars (for better recognition/reading)
        Beginning := Copy(NewName, 1, 19);
        Ending := Copy(NewName, 20, Length(NewName));
        NewName := Beginning + ReplaceRegEx(Ending, '[aeiou]', '', True, True);



  // shorten the 'NewName' if needed
     If Length(NewName) > NewNameLenght then
        SetLength(NewName,NewNameLenght);



  /////////////////////////////////////////////////////
  // Generate the output 'New Name' as you want:
     FileName := NewName + OldExt;
end.

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 2007-12-07 13:33

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

Re: Is there a way to truncate file names?

There is also an option to Select files which contain N characters or more (in their filename). Right-click on the files table, and open "Selecting..." menu, or use "Ctrl+L" shortcut. Once you select files with 100 or more characters, you can apply rules only for these files, like Stefan has already described.

Offline

Board footer

Powered by FluxBB