1 (edited by Stefan 2007-04-22 12:53:40)

Topic: Extract only the beginning of a string

Extract only the beginning of a string

For example we have some notice from our job and want give them away... but don't want let them know when we wrote the notices.

  From:
   Notice-1_2007.03.14.txt
   Notice-2_2007.03.17.txt
   Notice-3_2007.04.21.txt
   
   To:
   Notice-1.txt
   Notice-2.txt
   Notice-3.txt


    
     That's easy.
   
        Just use
     %b(1,8).*  [that mean the chars from 1 to 8]
   

       12345678
       Notice-1
_2007.03.14.txt    
    
   
Tip:
     You can use an trick in Siren to count the chars you need at easy:
     1. Hold the Shift-Key and click on the desired file name with the right mouse button. This pastes the current file name into the expression box.
         2. Place your cursor in front of the last char you want to keep
         3. Press Ctrl+P to displays the current cursor position in the status bar.

     [Press Ctrl+Z  -while you are in the expression box- to set the expression box back into the last state]







But what is if you can't count the chars because the lenght differs?    
   For example we have this file names and don't want the trailing numbers any more:
        
   From:
   A0B1C2DE_0201.jpg
   A1B#0302.gif

   To:
   A0B1C2DE.jpg
   A1B.gif

   Use the expression:
   %b(1,-5).%e



How does it work ?
   As we previously saw, the "()" modifier permits to define a start of extraction relative to the end of a string.
   The problem, here, is slightly different because this time it's the number of characters that must be relative to the length of the string.
   If you give to "number of characters" (2nd parameter) a negative value, the position of the last extracted character will be computed this way:
   length of the string minus the absolute value of the parameter.



   In our case, "%b" is:
   "A0B1C2DE_0201" so 13 characters
   "A1B#0302"          so   8 characters

   %b(1,-5) on "A0B1C2DE_0201" will be equivalent to:
   13 - 5 so 8 characters starting at position 1 gives "A0B1C2DE"

   %b(1,-5) on "A1B#0302" will be equivalent to:
   8 - 5 so 3 characters starting at position 1 gives "A1B"

   %e is the file extension



   So, following the expression for "A1B#0302.gif":
   %b                gives "A1B#0302"   [this is the hole base name without the extension]
   %b(1,-5)        gives "A1B"            [here we get the base name whit the last 5 chars cut off]
   %b(1,-5).       gives "A1B."           [we add an dot to set the extension apart]
   %b(1,-5).%e  gives "A1B.gif"        [at last we add the original expression too]


   --
   For more details just download Siren at http://www.scarabee-software.net/en/siren.html and consult the help.
   No installation needed, unzip and run. Siren stores it settings into an ini file.   <Here> you can see some screen shots of Siren.
   Enjoy Siren, the powerfully portable freeware renamer.