photools.com Community

IMatch Discussion Boards => General Discussion and Questions => Topic started by: afengler on November 29, 2022, 04:02:20 AM

Title: List of Categories in Text Format?
Post by: afengler on November 29, 2022, 04:02:20 AM
The Category Export module creates an XML file but what about a simple list in text format like a CSV file? Any suggestions?
Title: Re: List of Categories in Text Format?
Post by: Mario on November 29, 2022, 09:26:37 AM
The category export uses XML because this format allows to export categories with all their properties, including the files associated to each category. This makes it possible to exchange categories between databases and users, provide pre-made set of categories etc.

I assume you want a list of category names (paths)?

You can export the names of categories assigned to files via the Text Export using a {File.Categories} variable.

You copy the category names of the files currently selected in a File Window into the clipboard with the Copy Data app, using the same variable.

If you need this urgently, you can write a small app (or copy the code below into an existing app).
This short code fragment fetches all categories in the database and outputs their names to the console:

let res = await IMWS.get('v1/categories', {
    id: 'all',
    recursive: true,
    fields: 'path'
});

for (let c of res.categories) {
    console.log(c.path);
}

or you use this short PowerShell script.
Copy and paste into a text file, name it dump-categories.ps1 and run it.

$response = Invoke-RestMethod 'http://127.0.0.1:50519/v1/categories?auth_token=&id=all&fields=path'
$categories = $response.categories
foreach ($c in $categories)
{
    write-host "$($c.path)"
}
Title: Re: List of Categories in Text Format?
Post by: afengler on November 30, 2022, 04:03:52 AM
Thanks, Mario! The PowerShell script works perfectly...