I would like to generate an 8.3 filename (as used on DOS/FAT) without the modules win32api
or ctypes
(neither works with my configuration).
Currently, the code is this:
def short_names(names):
names2 = []
for i in names:
append_tilde = True
b = set(".\"/\\[]:;=, ") # ."/\[]:;=,[space] (forbidden chars)
old = i
for char in b:
i = i.replace(char, "")
if i == old: append_tilde = False
name_parts = i.split(sep=".")
name = ''.join(name_parts[0:len(name_parts)-1])
extension = name_parts[-1][0:3]
if len(name) > 6:
name = name[0:6]
append_tilde = True
if append_tilde:
for j in range(1,10):
if name.upper()+"~"+str(j) not in names2:
names2.append(name.upper() + "~" + str(j))
break
return names2
But it returns the "~1" part only, not the 6-character part plus "~1".
For the example input:
["Program Files", "ProgramData", "Programme", "Documents and Settings", "Dokumente und Einstellungen"]
it returns
['~1', '~2', '~3']
Intended return value:
["PROGRA~1", "PROGRA~2", "PROGRA~3", "DOCUME~1", "DOKUME~1"]
Python version: Python 3.10.1 (v3.10.1:2cd268a3a9, Dec 6 2021, 14:28:59) [Clang 13.0.0 (clang-1300.0.29.3)] on darwin
name
contain if there isn't an extension?Progra
,Progra
,Progra
,Docume
, andDokume
. However, that isn't happening...