Reading dir and files name on Win 10 - 64 ?
normally i use TXT file or py file all using the US character map
and no problems to read any dir of file name
but sometimes i receive files from someone else but they use French character set
is there a simple way to read the 2 character set in python ?
and is it possible to mix the 2 set in TXT file ?
thanks for any feedback
happy bl
here is code for my little script
> Blockquote
import bpy
import os
filewnam = 'Filename_list1.py'
fw = open(filewnam, "a")
fp = bpy.data.filepath
path1 = os.path.dirname(fp)
print ('path1 = ', path1 )
print ()
print ()
print ( ' files =', os.listdir(path1) )
print ()
print ()
print (' ### ######### ' )
print ()
import os
#path = "C:\\Blender\\2.79\scripts\\addons_contrib\\presets"
path = path1
print()
for (dirpath, dirnames, filenames) in os.walk(path):
print ("dirpath:", dirpath)
print ("filenames:",filenames)
print ()
print (' Walk path' )
print ()
print ()
ndir = 0
totfile1 = 0
for (dirpath, dirnames, filenames) in os.walk(path):
print ("dirpath:", dirpath)
# Write names to file
t1 = dirpath
fw.write("%s\n" % t1)
fw.write('\n') # adds empty line
# fw.write('\n') # adds empty line
ndir +=1 # # of dirs
jjf1 = 1
for f1 in filenames:
extension = os.path.splitext(f1)
filename, file_extension = os.path.splitext(f1)
# print ('extension = ', file_extension)
# print ('len =', len (file_extension))
if file_extension == '.jpg':
print ('files ', jjf1 , '= ',f1)
# Write file names
t1 = str(jjf1) + " , " + f1
fw.write("%s\n" % t1)
jjf1+=1
totfile1 +=1
fw.write('\n') # adds empty line
print ()
print ()
print ('# of dir ', ndir )
print ()
print ('# of files ', totfile1 )
t1 = '# of dir ' + str(ndir)
fw.write("%s\n" % t1)
fw.write('\n') # adds empty line
t1 = '# of files ' + str(totfile1)
fw.write("%s\n" % t1)
fw.close()