← Back to team overview

zim-wiki team mailing list archive

Re: Attachments management


Hi folks.

Zim was developed with Python for a reason. When you are on Xubuntu, you are alreadily provided with a working python interpreter. From your answer – Alessia – I conclude that you are new to textual programming but without fear. Maybe you try this:
(1) apt install scite
(2) startup scite and create a file called count_zim_attachments.py
(3) insert some initial content into your python script

### start of file; exclude this line
#!/usr/bin/env python

import os

start_directory = '.'  # i put the script right into my zim notebook and start it inside in *this* directory '.' you may note any path of a notebook or a subdirectory in a notebook between the single quotes.

total_attachments = 0
for current_directory, sub_directories, sub_files in os.walk('.'):
                attachments = [f for f in sub_files if not f.endswith('.txt')]
                total_attachments += len(attachments)
                if attachments:
                                print('{} containts {} attachments.'.format(current_directory, len(attachments)))

print('{} attachments found in {}'.format(total_attachments, os.path.abspath(start_directory)))

### end of file; exclude this line

(4) Inside Scite press F5 key. Scite attempts to execute the script and presents the script and the script’s output (print) side by side. If you have any problems on this step, drop me a pm and I will assist you via Teams or Skype.

The script assumes, that any txt file is zim content. It assumes, that any non-txt-file is an attachment. Your mileage on these assumptions may vary.

Please do not hesitate to ask questions while adapting this script to your personal case.

Sincerely, mayk.