#1 2013-01-12 06:14

UCG Musician
Member
Registered: 2013-01-12
Posts: 5

Using Part of Filename to Identify Folder For Renamed File

This is similar to another post but I can't figure out how to apply it in my case.  I have a large number of files that I work with as part of a church hymnal.  The hymnal has 190 hymns.  I am arranging it for 22 different types of instruments.  Each of the 190 hymns thus has 22 files for each of the instruments.  When I work on these files I start with one that has a name such as:
"043 - Sing Songs of Praise to Him - 01 Interim - SR - 2011-08-28"

This file is the beginning stage of arranging for the first instrument.  The first 3 digits are the hymn number in the hymnal.  The next part is the hymn name.  The "01 Interim" is part of an instrument naming scheme that I use.  "SR" stands for "simplified rhythms" and is used to distinguish these hymns from the "original rhythms" that were in the vocal hymnal.  The last part, of course is the date.

The program I use (Finale) has a great deal of automation capability and I proceed from one instrument to the next by invoking a script.  I do not change the script every time it's a new day and therefore a new date.  Thus the date that becomes part of the filename is not accurate.  When I discovered ReNamer I learned that I can keep that incorrect date and simply fix the filename to replace it with the current date.  I have become very dependent on ReNamer for this application.

After arranging the hymn for the first instrument in sequence, the file is saved as:
"043 - Sing Songs of Praise to Him - 04 Fl & Picc - SR - 2011-08-28"
From this file, I create the next instrumental arrangement and the reworked file is then saved as:
"043 - Sing Songs of Praise to Him - 08 AltoFlute - SR - 2011-08-28"
The process continues until I have all 22 versions saved in a folder.

Then I use ReNamer to fix the date.  So far, so good.  But after each file is named correctly it must be moved from a temporary folder to the folder for all that instrument's files.  The folder that contains the 22 files I have just worked on is:

F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Temporary Folder for File Processing

The name of the folder for all the "01 Interim" files is:
F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Final Versions by Instrument\01 Interim

The name of the folder for all the "04 Fl & Picc" files is:
F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Final Versions by Instrument\04 Flute & Piccolo

The name of the folder for all the "08 AltoFlute" files is:
F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Final Versions by Instrument\08 Alto Flute

During renaming I would like to also move each file to the correct folder if this can be done.  Each filename contains the instrument "number" like 01 or 04 or 08.  Each final folder also contains that number.

Thus, I would like to go from:
F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Temporary Folder for File Processing\043 - Sing Songs of Praise to Him - 01 Interim - SR - 2011-08-28
To:
F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Final Versions by Instrument\01 Interim\043 - Sing Songs of Praise to Him - 01 Interim - SR - 2013-01-12 (current date).

Can this be done and, if so, please help me understand what rules would accomplish it in ReNamer.

Thank you,
Randy

Offline

#2 2013-01-12 11:13

narayan
Senior Member
Registered: 2009-02-08
Posts: 471

Re: Using Part of Filename to Identify Folder For Renamed File

Hi Randy,

Welcome aboard!

You can use the "Rearrange" rule with delimiter as " - " (two spaces sandwiching a hyphen, without the quotes).
ReNamer chops the original name and names each part as $n.
These tokens can be used in any formula, with literal text.
You can also use a backslash \ to create a folder system of any depth.

For example, assume the original name is:
043 - Sing Songs of Praise to Him - 01 Interim - SR - 2013-01-12

And we use the rename formula as:
$3\$2 ,processed on $5

This will result in the following:
1. ReNamer will create a "01 Interim" subfolder in the current folder.
2. The file will be renamed to "Sing Songs of Praise to Him, processed on 2013-01-12", and placed in the subfolder.

Since you already have scripting skills, I guess this will get you started. HTH.

BTW your folder scheme seems to be too complicated.
The file need not be named after its status. We don't name a child "John born premie in Hamburg - 17th October 2005"

Also, strip the Hymn name from the file-names.
Instead, store all files for a given Hymn in a common folder that is named after the Hymn.

Within each Hymn folder, create mirror folder structures for each stage of the file.
As each file is processed, move it to the folder meant for the next stage.

-And so on.

Last edited by narayan (2013-01-12 11:17)

Offline

#3 2013-02-21 03:01

UCG Musician
Member
Registered: 2013-01-12
Posts: 5

Re: Using Part of Filename to Identify Folder For Renamed File

I am reposting this because I cannot figure out how to apply what Narayan suggested.  I have experimented with the rearrange command and am able to break up the file names into usable variables but I cannot figure out how to change the file path.  I do appreciate Narayan's help and the suggestion that my file path structure does not make a lot of sense to others, but it is what it is and I need to retain it in order to not create additional work.

That being said, I need to rename as follows.
Example 1, from:
F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Temporary Folder for File Processing\043 - Sing Songs of Praise to Him - 01 Interim - SR - 2011-08-28
To:
F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Final Versions by Instrument\01 Interim\043 - Sing Songs of Praise to Him - 01 Interim - SR - CURRENT DATE

Example 2, from:
F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Temporary Folder for File Processing\043 - Sing Songs of Praise to Him - 04 Fl & Picc - SR - 2012-11-30
To:
F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Final Versions by Instrument\04 Flute & Piccolo\043 - Sing Songs of Praise to Him - 04 Fl & Picc - SR - CURRENT DATE

Example 3, from:
F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Temporary Folder for File Processing\043 - Sing Songs of Praise to Him - 08 AltoFlute - SR - 2013-01-13
To:
F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Final Versions by Instrument\08 Alto Flute\043 - Sing Songs of Praise to Him - 08 AltoFlute - SR - CURRENT DATE

I would appreciate if someone can explain how to extract the instrument designation (e.g., "04 Fl & Picc") and use the "04" part of it to construct the correct file path where the folder is "04 Flute & Piccolo".

As long as I can follow the logic, I am happy to write as many rules as it takes to get from A to B.  Once that's done, it will save me a vast amount of time in the long run.

Thank you,
UCG Musician

Offline

#4 2013-02-21 09:50

narayan
Senior Member
Registered: 2009-02-08
Posts: 471

Re: Using Part of Filename to Identify Folder For Renamed File

Well, your first example does not exactly match the others, so here is an approximate solution (you can adapt it easily to get what you want.)

The basic idea is to use two rules:

(a) The Rearrange rule lets you enter a base path (F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Final Versions by Instrument\) in the new pattern. It will be treated as literal string. Add the token-based string to it to form the complete new expression.

(b) the PascalScript rule lets you add the system date.

****
So here is the actual process:

Select Rearrange rule.
Enter " - "  (without double-quotes)in the split using box.
Leave the Delimiter radio button selected.

In terms of your first example,
043 - Sing Songs of Praise to Him - 01 Interim - SR - 2011-08-28
$1=043
$2=Sing Songs of Praise to Him                                         
$3=01 Interim
$4=SR
$5=2011-08-28

So the new pattern would be:

F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Final Versions by Instrument\$3\$1 - $2 - $3 - $4 -

(depending on your examples, you MAY want to omit $3)

Now add another rule.
In the dialog that pops up, select "PascalScript" option from the rule list (at left).

In the right pane, if there is any text, first delete it.
Then enter the following code (copy from here and paste):

var
  DateTime: TDateTime;

begin
  DateTime := Date;
  FileName := WideExtractBaseName(FileName) +
    FormatDateTime(' (dd-mmm-yyyy)', DateTime) +
    WideExtractFileExt(FileName);
end.

Click the "Save the rule" button at the bottom.

Check the result. Modify the string as needed.

HTH.

Last edited by narayan (2013-02-21 10:09)

Offline

#5 2013-02-21 10:12

narayan
Senior Member
Registered: 2009-02-08
Posts: 471

Re: Using Part of Filename to Identify Folder For Renamed File

P.S. Here is the pascal code for date in YYYY-MM-DD format without parentheses.
So you can use the following code instead:


var
  DateTime: TDateTime;

begin
  DateTime := Date;
  FileName := WideExtractBaseName(FileName) +
    FormatDateTime(' yyyy-mm-dd', DateTime) +
    WideExtractFileExt(FileName);
end.

Offline

#6 2013-02-21 12:24

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

Re: Using Part of Filename to Identify Folder For Renamed File

I think the major problem is on changing the names of the instruments for the folders isn't it?
Take a look at the //comments, especially on the InstrumFolder replacements, and see if it works...

const
  // Change the destination path here.
  TargetPath = 'F:\Randy\Church\Local\Music\Sequences\UCG New Hymnal\Instrumental Versions\Final Versions by Instrument';

var
  Parts: TStringsArray;
  BaseName, Ext, InstrumFolder: WideString;

begin
  // Load main vars
  BaseName := WideStripExtension(FileName);
  Ext := WideExtractFileExt(FileName);
  FileName := '';
  
  // Read the parts of the base name
  Parts := SubMatchesRegEx(BaseName, '^(.+?) - (.+) - (.+?) - (.+?) - (.+?)$', False);
  BaseName := '';
  
  if (length(Parts) = 5) then
  begin
    // Below here you can extend the name of the folder instruments.
    InstrumFolder := Parts[2]; // Arrays start in 0.
    InstrumFolder := WideReplaceText(InstrumFolder, 'Fl & Picc', 'Flute & Piccolo');
    InstrumFolder := WideReplaceText(InstrumFolder, 'AltoFlute', 'Alto Flute');
    InstrumFolder := '\' + InstrumFolder + '\';
    
    // Just rebuilding the base name
    BaseName := Parts[0] + ' - ' + Parts[1] + ' - ' + Parts[2] + ' - '
      + Parts[3] + ' - ' + FormatDateTime('yyyy-mm-dd', Date);
    
    // Return the full path to place the file in the desired folder.
    FileName := TargetPath + InstrumFolder + BaseName + Ext;
  end;
end.

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

Offline

#7 2013-02-23 05:15

UCG Musician
Member
Registered: 2013-01-12
Posts: 5

Re: Using Part of Filename to Identify Folder For Renamed File

Thank you to all who helped explain how to do this.  I am happy to report that through a combination of your suggestions and the understanding I finally gained, the problem has been solved.  I just successfully renamed 23 files and moved them to the existing folders I had set up.  I verified that every single file was correctly renamed and went to the right place.

As I said before, this will save me a vast amount of time in the long run.  Thank you very much!

Offline

#8 2013-02-24 03:52

narayan
Senior Member
Registered: 2009-02-08
Posts: 471

Re: Using Part of Filename to Identify Folder For Renamed File

Glad to help!

Here is a additional labor-saving trick:

You can save the rules as a preset (ReNamer automatically assigns a shortcut, like CTRL+1, CTRL+2...)
So next time all you have to do is to load the files and press the shortcut.

*****
In fact, the ultimate labor-saving trick is to launch ReNamer right from your explorer, using a Commandline mode.

HTH.

Last edited by narayan (2013-02-24 03:55)

Offline

Board footer

Powered by FluxBB