Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] Lazarus - Short procedure to remove offending file/path characters
Delphi, Lazarus, Free Pascal
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
December 17, 2015 8:48 AM
This is a quick function that converts so called "offending" characters of a filename or path to an escaped character sequence.
MacOS X allows a lot of characters but converts the offending ones to an escaped character.
For example a space in a filename or path will be escape as " ".
Since there are a bunch of characters to which this applies, I decided to write a tiny routine to catch all offending filenmae/path characters and replace them with escaped ones. Feel free to post improvements.
Note:
This was originally written for MacOS X, but I'm sure it will be comparable for Linux. For Windows, I really have no idea if this will work.
function EscapePath(path:string):string;
var newpath, SpecialChars:string;
Ch:char;
begin
SpecialChars:='!?&*@$|:;{}<>()[]`''" '; // the offending character list
newPath:=path;
for Ch in SpecialChars do
newpath:=StringReplace(newpath,Ch,''+Ch,[rfReplaceAll]);
EscapePath:=newpath;
end;