earnestt1234 / seedir

A Python package for creating, editing, and reading folder tree diagrams
MIT License
120 stars 9 forks source link

Filtered characters in fakedir refers to Windows systems only #30

Open gitvavo opened 2 weeks ago

gitvavo commented 2 weeks ago

When parsing a text file containing file and folder names, a number of characters get stripped from names which refers to forbidden characters in Windows systems:

https://github.com/earnestt1234/seedir/blob/300a22ddae5114e19335e2be99f9faecc7e7616d/seedir/fakedir.py#L1370

It would be nice to import platform and defines the filtered chars based on the current system (or through a parameter), i.e.:

import platform

if platform.system()=='Windows' bad_chars='/:?"*<>|'
if platform.system()=='Linux' bad_chars='/'
filtered = "".join([c for c in keyboard_chars if c not in bad_chars])

EDIT: The list of filtered characters can indeed be bypassed by providing start_chars, so this is not really an issue, sorry!

earnestt1234 commented 4 days ago

Thanks for raising this. Even if there is a workaround with start_chars and/or name_chars, that is not entirely obvious. I like your approach for making parsing more automatic across systems, though I wonder if having the algorithm dependent on the operating system could lead to some unexpected results for reproducing things.

I would like to rewrite/refactor this whole function TBH - it's very old code and I've refrained from touching it since it works for most typical cases I've tried. But it's not very readable.

Next time I work on this, I will have a look at this function and keep this issue in mind. Let me know if using start_chars/name_chars has ended up not being a good approach for you.