List of Categories in Text Format?

Started by afengler, November 29, 2022, 04:02:20 AM

Previous topic - Next topic

afengler

The Category Export module creates an XML file but what about a simple list in text format like a CSV file? Any suggestions?

Mario

#1
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)"
}
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

afengler

Thanks, Mario! The PowerShell script works perfectly...