Author Topic: File Name Character Count Column  (Read 6012 times)

0 Members and 1 Guest are viewing this topic.

RW

  • Newbie
  • *
  • Posts: 4
File Name Character Count Column
« on: July 21, 2015, 06:26:04 PM »
I get a bunch of pdfs from various people and I would like to find all the ones that do not follow a particular naming pattern. 
For example, I want all my files to be a certain length depending on the type of pdf I receive. 
Mostly, I want them to be exactly 10 characters and labeled like this "00005_0001.pdf"

However, some people send me files labeled like this:
05_01.pdf
005_001.pdf
0005_001.pdf
5_1.pdf

I would like to be able sort on a Filename Character Count column so that I can easy see all the ones with the same character count grouped together. 
Would it be possible to create a column that could calculate this?  Also, this column would need to able to be exported to a csv file, so that I could create a BAT file to rename them easily.

RTT

  • Administrator
  • *****
  • Posts: 907
Re: File Name Character Count Column
« Reply #1 on: July 22, 2015, 12:40:39 AM »
You may use the batch rename tool, and fix these names from PDF Explorer itself.
For the above name examples, a script like this:
Code: [Select]
function Fixname() {
    //remove path
    var filename = BatchFile.Filename.substring(BatchFile.Filename.lastIndexOf('\\') + 1);   
    //remove extension
    filename = filename.substring(0, filename.lastIndexOf('.'));
    var fParts = filename.split('_');
    if (fParts.length == 2) {
        var v1 = parseInt(fParts[0]);
        var v2 = parseInt(fParts[1]);
        if (v1 != NaN && v2 != NaN) {
            return lPad(v1, 5) + '_' + lPad(v2, 4);
        }
    }
    return filename
}

function lPad(n, width, z) {
    z = z || '0';
    n = n + '';
    return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
can be used by this tool to fix these names easily.

Select all the files that need to be checked, even the ones with correct names, and start the batch rename tool. Now click the right pointing arrow button at the right of the rename formula field, and, from the popup menu, click the item "Scripts>ManageScripts".
Now create a new script and name it Fixname, and paste the above script in the script editor (check the first attached screenshot how it should look like). Close the editor, saving the changes.

In the renamer tool, make reference to that function in the "rename formula" field by typing the function name inclosed in square brackets, i.e. [Fixname]. Visually check if all the new names are correct, and run it.

If indeed you want to use the column method you proposed, you may use the Edit Info Fields batch tool for this.
Just set a custom field to hold this value, by creating a custom grid layout, to properly name, and include, a custom field in the grid). Now start the edit info field batch tool, selecting all the files you want to process, enable the field you will use to hold the value, and, as in the above example, start the script manager and create a NameLength named script:
Code: [Select]
function NameLength() {
    //remove path
    var filename = BatchFile.Filename.substring(BatchFile.Filename.lastIndexOf('\\') + 1);   
    //remove extension
    filename = filename.substring(0, filename.lastIndexOf('.'));
    return filename.length;
}
Close, saving it, and back on the edit info fields tool make reference to that function by typing [NameLength] in that custom field. Tick also the "DB only" checkbox, in order to update the column only in the database (it's a working column, so no need to edit the value in the PDF itself).
Run the tool, and you will have now that custom field column showing the length of the filenames, you can then use to sort and export to a csv file.