I want to loop over all files in a directory. I tried glob:
from glob import glob
for filename in glob('*'):
print filename
and I tried fnmatch:
import fnmatch
import os
for file in os.listdir('.'):
if fnmatch.fnmatch(file, '*'):
print(file)
If the filename contains a german character (ä,ö,ü,...) then the print function prints an empty line. How can I handle int'l characters in this case?
UPDATE
Works in GIMP 2.10.16 Python-Fu Console 2.7.17 on Debian, but not on a Windows system (same versions).
And I only get the blank line the 2nd time I paste and execute the script in the console. The first time after GIMP/Pythen-Fu start, a lot of error messages are displayed in the file list, instead of the correct filenames:
C:\Users\jamacoe\AppData\Local\Programs\GIMP 2\lib\gimp\2.0\plug-ins\python-console/pyconsole.py:74: GtkWarning: gtk_text_buffer_emit_insert: assertion 'g_utf8_validate (text, len, NULL)' failed
self.buffer.insert_with_tags_by_name(pos, text, self.tag_name)
C:\Users\jamacoe\AppData\Local\Programs\GIMP 2\lib\gimp\2.0\plug-ins\python-console/pyconsole.py:74: GtkWarning: Invalid text buffer iterator: either the iterator is uninitialized, or the characters/pixbufs/widgets in the buffer have been modified since the iterator was created.
You must use marks, character numbers, or line numbers to preserve a position across buffer modifications.
You can apply tags and insert marks without invalidating your iterators,
but any mutation that affects 'indexable' buffer contents (contents that can be referred to by character offset)
will invalidate all outstanding iterators
self.buffer.insert_with_tags_by_name(pos, text, self.tag_name)
C:\Users\jamacoe\AppData\Local\Programs\GIMP 2\lib\gimp\2.0\plug-ins\python-console/pyconsole.py:74: GtkWarning: gtk_text_buffer_apply_tag_by_name: assertion 'gtk_text_iter_get_buffer (end) == buffer' failed
self.buffer.insert_with_tags_by_name(pos, text, self.tag_name)