Format for path in 'v1/files'?

Started by Carlo Didier, November 22, 2017, 09:50:02 PM

Previous topic - Next topic

Carlo Didier

I can't find out which format the 'path' parameter should have if I want to get all the files in a folder.

I have
Quote"D:\\Photos\\Photos Carlo\\2003\\09\\2003-09-13 Michel\\"
as result from "IMatch.folderBrowser({..."

When I pass that to
IMatch.get('v1/files',{
    path: response.folder[0],
    fields:'id,name'
}).then(function(response) {
    console.log(JSON.stringify(response,null,2));
});

I get this result:
Quote{
  "files": [],
  "hiddenByStacks": 0
}
with "files" an empty array instead of a file list.

Here is the whole code sequence:
        $('#SelectFolder').click(function() {
            IMatch.folderBrowser({
                initialselection: '1',
                allowmultisel: 'false'
            }).then(function(response) {
                if (response.result == 'ok') {
                    $('#SourceID').text(response.id);
                    $('#SourcePath').text(response.folder[0].replace('\\\\/g','\\'));
                    strPath = response.folder[0];
                    console.log(JSON.stringify(strPath,null,2));
                    arrPath = response.folder[0].split('\\');
                    $('#NewName').val(arrPath[arrPath.length - 2]);

                    // try to build range from images in source folder

                    IMatch.get('v1/files',{
                        path: response.folder[0],
                        fields:'id,name'
                    }).then(function(response) {
                        console.log(JSON.stringify(response,null,2));
                    });
                }
            });
        })

Carlo Didier

Hmm, I found that this returns a list with all the files in a folder, but then I bump into the problem that I can't access the file list in the returned objet ...
            IMatch.folderBrowser({
                initialselection: '2270',
                allowmultisel: 'false'
            }).then(function(response) {
                if (response.result == 'ok') {

                    // try to build range from images in source folder

                    IMatch.get('v1/folders/files',{
                        path: response.folder[0],
                        sortby: 'filename',
                        fields:'id,name,children'
                    }).then(function(response) {
                        console.log(JSON.stringify(response.folders,null,2));
                    },
                    function(error){
                        console.log(error);
                        console.log(JSON.stringify(error));
                    });
                }
            });


gives me
[
  {
    "id": 2270,
    "path": "D:\\Photos\\Photos Carlo\\2015\\04\\2015-04-04 Landscapes\\",
    "name": "2015-04-04 Landscapes",
    "files": [
      {
        "id": 86733,
        "name": "D20150404001.dng"
      },
      {
        "id": 86734,
        "name": "D20150404002.dng"
      },
...


but then console.log(JSON.stringify(response.folders.files,null,2));
returns null

Why?

thrinn

response.folders is an array. You try to access a property files of this array, not of an element in this array.
Try
console.log(JSON.stringify(response.folders
  • [/b].files,null,2));
    to get the files in the first folder in the array.
Thorsten
Win 10 / 64, IMatch 2018, IMA

Carlo Didier

Quote from: thrinn on November 23, 2017, 08:35:36 AM
response.folders is an array. You try to access a property files of this array, not of an element in this array.
Try
console.log(JSON.stringify(response.folders
  • [/b].files,null,2));
    to get the files in the first folder in the array.
Ahh, that did it! Thanks!
I didn't get that from the structure it showed me. I missed the "[" at the very beginning ...