Export Imatch Directories to a Excel file

Started by kiwilink, December 19, 2022, 12:42:52 PM

Previous topic - Next topic

kiwilink

I would like to export all the directories and subdirectories of my Imatch database into Excel so I can do column sorts on directory names, extensions, etc.  Is there a way to do this from within Imatch (export my media folders to a spreadsheet or maybe also export my categories) so I can do sorts and prints.

I remember a very long time ago there was a print function that would print the folder structure. I tried to figure out how to do it using Text Export but couldn't figure it out.

Thanks!

Kiwilink

Mario

You say you want to export folder names (?).
In the second sentence you say you want to sort by extensions, which is part of the file names, not folders.
What do you want to export?

If you want to export data for files, use the text export. It allows you to export the folder name, fully qualified path, file extension etc. If the data volume is low, you can also use the Copy Data App and copy the data from the clipboard into Excel.

To copy individual folder names into the clipboard, select the folder(s) and press <Crl>+<C>.

IMatch has no built-in features to export folder names or category names as text, because this is not something that is often needed.

If needed, a list of folders and categories can be easily produced using standard Windows PowerShell.

List all folders:

$response = Invoke-RestMethod 'http://127.0.0.1:50519/v1/folders?auth_token=&id=all&recursive=true&fields=path'
$folders = $response.folders
foreach ($f in $folders)
{
    write-host "$($f.path)"
}

List all categories:

$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)"
}

Copy and paste each script into Notepad and save under "list-folders.ps1" and "list-categories.ps1".
Open a PowerShell command line from the Search menu and change the directory to the directory containing the scripts.

Run them like
.\list-categories.ps1
If PowerShell complains about execution policy (scripts not allowed to run), execute this command before:

Set-ExecutionPolicy RemoteSigned -Scope Process
Start IMatch before running the scripts.

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

kiwilink

Mario:

Thank you for taking the time o respond.  Yes, I was mostly trying to get the folder names.  I followed the instructions and I got the following error.  I'm trying to research what went wrong.  See attachment..  I did have IMATCH running.  If I get it to execute will I be able to cut and paste from Powershell to Excell (or export)?  Thanks.

PS:  5 or 6 years ago there was a command in IMATCH that generated a report on the database.  Is that a possibility to run that?

Mario

As I wrote, when this happens, you have to run

Set-ExecutionPolicy RemoteSigned -Scope Process
before running the script. Windows does by default not allow users to run scripts for security reason.

Quote5 or 6 years ago there was a command in IMATCH that generated a report on the database.
I have no idea. Maybe some script?
What would such a report be good for? The diagnosis does a report, the Dashboard lists all details about your database.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

thrinn

Quote from: kiwilink on December 19, 2022, 04:14:26 PMI followed the instructions and I got the following error.  I'm trying to research what went wrong.
From the screenshot I guess it is not a problem with the Set-ExecutionPolicy. This (first) command run without errors. Please double check if the name of the script is correct, and if the script is really saved in C:\Users\Mikey\Documents.
Thorsten
Win 10 / 64, IMatch 2018, IMA

thrinn

Quote from: kiwilink on December 19, 2022, 04:14:26 PMIf I get it to execute will I be able to cut and paste from Powershell to Excell (or export)? 
I am no Powershell expert, but you can redirect the output of a script to a file:

.\list-categories.ps1 6> test.txt
Thorsten
Win 10 / 64, IMatch 2018, IMA

kiwilink

Thanks everyone for helping.  The reason for wanting to print it is so I can do some verification on my images.  I have 1430 directories with 110,000 images in them.  I am going to do some cleanup and I wanted to write notes on the directories of what I am consolidating.  After 2 hours with Powershell I just went with a freeware program,  Thank you all!

Mario

What did this "freeware" program do that the PowerShell script did not?
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

kiwilink

Mario:

I used DirPrintOK 6.65 and it let me specify how many levels (Directories and subdirectories) I wanted to export to a spreadsheet.  It took only a few seconds to run and no errors.  I spent about an hour trying to get Powershell to run via the prompt and got a LOT of errors (mostly because I wasn't familiar with the syntax (not a PowerShell User).  I will go back and try it again because I have hundreds of categories in IMATCH and I'd like to clean them up on paper and then use IMATCH to move things around.  I added a screencapture of what it looked like.  If you want me to delete this and the name I can do that.  I was just adding it to show you why I chose it over Powershell.

Thanks!

Kiwilink 

Mario

I still don't know what problems you are facing.
Maybe I just repeat the steps.

Open Windows Notepad. Copy & Paste the script code from my post above into Windows Notepad.
Use the Save command in Windows Notepad to save the script text to a file in a folder of your liking.
For example, save it to "My Documents" under the name dump_categories.ps1

Press <Windows>+<R> on your keyboard.
Type

powershell

and press <Enter>
A black console Window opens.

Type

cd "my documents"

and press <Enter>

Now, type .\ dump_categories.ps1  and press <Enter>

If Powershell prints errors in red about "Cannot run scripts" or similar, enter this command and press <Enter>

Set-ExecutionPolicy RemoteSigned -Scope Process

This is probably what caused issues on your end.
Normal (aka non-admin) users are no longer allowed to run scripts in Windows. For  security reasons.
Apparently users run script commands they receive in emails from Nigerian princes all the time, compromising security ::) ;D
So Microsoft disabled running scripts by default.

Now type

.\ dump_categories.ps1

again and press <Enter>

This lists all the folders in the database in the console.
If you need this as a text file, use

.\ dump_categories.ps1  6>  cats.txt

instead. Now you can open the file in Excel as "My Documents\cats.txt"

I understand that If you have never used a command line before, this may seem a bit complicated. Typing commands on the console etc.
But that's just how things gets done quickly, without downloading arbitrary software from potentially unsafe sources.

IMatch databases are fully accessibly not only from IMatch apps or JavaScript but also from simple PowerShell commands in Windows. This makes rather unusual requests like your's easy to solve, without 3rd party software.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

kiwilink

#10
Mario:

I'm such an idiot.  After hours of trying to learn all about Powershell, it finally hit me!  I had to start IMATCH and then run the scripts.  I was running them (not being smart enough to realize IMATCH must be running in the background).  Once I did this everything worked perfectly.

I am so sorry and I apologize for being so naive. 

Thank you for helping me.  I am cleaning up my categories using my newly outputted spreadsheet.

This unbelievable and always dependable support is why I will always be a IMATCH registered user.  Thank you Mario and please forgive me if I wasted your time on this.

Kiwilink

PS:  Thank you Thrinn for your help😀

Mario

#11
Yeah, well...I didn't think about mentioning this, sorry. I now updated the corresponding post in the App board.

The PowerShell scripts access your database via IMatch Anywhere WebServices (IMWS), which are integrated in IMatch.
If IMatch is not running, IMWS is not running and no access to your database is possible.

One of the beautiful features of IMWS in IMatch is not only that it makes all the cool apps possible (and the People View, Event View, File Window Gallery), but that it basically allows all programming languages to read and modify IMatch databases.

Like, in this case, Windows PowerShell. I also often use Python scripts to access IMatch database contents, or a plain web browser. The only requirement is that IMatch is running (or IMatch AnywhereTM).

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook