PDF Explorer > General

Custom script keywords for directory listing and loading text

(1/3) > >>

Padanges:
Hi,
I want to write a script which by given BatchFile.Filename looks in current file directory for other files with the same name but different file extensions (let's call them "family files" :) ) and returns the number of them. How can I do that?
In addition to that, is it possible to load text lines into BatchFile.Filename DB entry's Info field if it finds file (among those listed) named, for example, "descript.ion"?

Thanks in advance.

RTT:

--- Quote from: Padanges on August 27, 2016, 07:59:14 AM ---I want to write a script which by given BatchFile.Filename looks in current file directory for other files with the same name but different file extensions (let's call them "family files" :) ) and returns the number of them. How can I do that?

--- End quote ---
OT: Do you have experience with any coding language?

Here is a My Scripts script that works on that idea. For all the files selected in the grid, it will find the "family files" and report the number and names, if any found.

--- Code: ---var wsh = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");

function getFolderFilesList(folderName, pattern) {
    var TemporaryFolder = 2;
    var ForReading = 1;
    var tmpFile = fso.GetSpecialFolder(TemporaryFolder) + '\\dirout.txt';
    var command = '%comspec% /c dir /on /b "' + folderName + '\\' + pattern + '">"' + tmpFile + '"';
    wsh.Run(command, 0, true);
    if (fso.FileExists(tmpFile)) {
        var f = fso.OpenTextFile(tmpFile, ForReading);
        var dirlist = [];
        while (!f.AtEndOfStream) {
            var filename = f.ReadLine();
            if (fso.FileExists(fso.BuildPath(folderName, filename))) {
                dirlist.push(filename);
            }
        }
        f.Close();
        fso.DeleteFile(tmpFile);
        return dirlist
    }
}

var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    ProgressBar.position = i + 1;
    var file = pdfe.SelectedFiles(i);
    var folderName = fso.GetParentFolderName(file.filename);
    var list = getFolderFilesList(folderName, fso.GetBaseName(file.filename) + '.*');
    if (list.length > 1) {
        var baseExt = fso.GetExtensionName(file.filename);
        var filename = fso.GetFileName(file.filename);
        var plist = [];
        for (var n = 0; n < list.length; n++) {
            if (fso.GetExtensionName(list[n]) !== baseExt && list[n] != filename) {
                plist.push(list[n]);
            }
        }
        if (plist.length > 0) {
            pdfe.echo(file.filename + ' has ' + plist.length + ' family files');
            for (n = 0; n < plist.length; n++) {
                pdfe.echo('   ' + plist[n]);
            }
        }
    }
}
pdfe.echo('All checked');

--- End code ---

--- Quote ---In addition to that, is it possible to load text lines into BatchFile.Filename DB entry's Info field if it finds file (among those listed) named, for example, "descript.ion"?

--- End quote ---
No, the filename field is read only, and I'm not getting the idea here!
From the script you can edit the metadata fields too, and so store theses names in a custom field.

Padanges:

--- Quote ---Do you have experience with any coding language?
--- End quote ---
Some. Nothing too extensive though.


--- Quote ---No, the filename field is read only, and I'm not getting the idea here!
--- End quote ---
I'll try to say it differently: the idea is to have a column "Description" which would for a current entry look for *FileName*.description.txt (or, in general, for a "descript.ion" file) in the parent folder and (if the file exists) load the file content into the DB info field.

Padanges:
OK, after checking-out your code I realized how can we make two quite general and useful tools: 1) Common folder files; 2) load entry info from file.

1) First of all, I need to get "related file" file mask prompt, where the mask default is "filename.*" (other possible cases: "filename.anyExactExt", "*.anyExactExt", "anyExactFilename.anyExactExt", "*.*"). Then to get common folder file list for the given pattern (excluding the current grid entry filename file from the list). Finally, print such results: $gridEntryFilename has $resultListFileCount related files: $resultList.

2) Get the filename and column name promt, where user specifies "ANYexactFILENAME.ANYexactEXT" and chooses current layout custom info field from combo-box. Then search for the given $filename in common folder and load it's content to given $column entry field. Finally, print such results: $gridEntryFilename related info file loaded; or: $gridEntryFilename related info file not found.

And that's a lot of new trick to learn...

RTT:

--- Quote from: Padanges on August 29, 2016, 12:35:07 PM ---I'll try to say it differently: the idea is to have a column "Description" which would for a current entry look for *FileName*.description.txt (or, in general, for a "descript.ion" file) in the parent folder and (if the file exists) load the file content into the DB info field.

--- End quote ---
So you are talking about retrieving the metadata information stored in descript.ion files?
It seems these files don't have a fixed specification, so it would be tricky to parse the various variants. For descript.ion files with "Filename" "description" lines, doesn't seems too complicated to create such a script to put all the description data in a description named field. Have you tried already? Show me some code, if you are facing specific problems.

Navigation

[0] Message Index

[#] Next page

Go to full version