Nextcloud-client gives an error like “Filename contains trailing spaces when a user has uploaded a file or folder with a “forbidden” character like a space in the front. At our school we work with 3 different OS’es: Mac, Windows and Linux. They all use different filesystems: hfs, ntfs and btrfs. The Nextcloud-server is hosted on openSUSE Linux so it supports most of “forbidden” characters. But off course… Windows does not. A user using MacOS can perfectly upload a file named: " kaka>! crazy°due .pdf
” but another user, who this file is shared with using Windows, cannot sync this file and gets an error in the sync app.
I get this error the whole time since MacOS users can put anything into a file of folder name… So renaming file by file is so much work I would get a depression. So my question to you geniuses out there… Can we write some Bash script that I can put in a cronjob running every night so when a user used these “forbidden characters” there will be automatically converted into “_” or in the case of leading or trailing or invisible spaces just be deleted?
I know it is possible by using some regex in some loop function converting all forbidden chars like ['?', '<', '>', ':', '*', '|', '"', chr(0), "\n", "\r"
] into “_” or just removing them from the “forbidden string”…
Just I am not so experienced in writing this kind of scripts…
Has anyone done this before? And are you willing to share this bash script with me? I would be really thankful for any advice accomplishing this.