In Windows XP , it is possible to use "/" instead of "\" . Therefore , it is NOT necessary to make two different file path representations . I am not using any Windows now , therefore I can not say anything about last Windows versions .
It is very easy to check whether "/" is usable on your Windows : Use a file path with "/" . My opinion is that it will find the related file assuming that your file path is correct other than "/" . Mehmet Erol Sanliturk On Tue, Oct 29, 2019 at 2:25 PM Bo Berglund via lazarus < lazarus@lists.lazarus-ide.org> wrote: > I am writing a console application intended to be portable between > Windows and Linux and it uses files on the file system for > configuration and also for processing data. > > Since the path delimiter is different on Unix and Windows I believe I > have to handle this in my code, but how? > > I could create all paths inside the application using Windows > delimiters and then upon usage send them to a "platform filter" like > FixPlatformPath() below, which returns the string with the proper > delimiters for the platform. > Or else I have to check wherever the paths are dealt with and put > conditionals inside the code in many places. > Either way it feels a bit convoluted. > > Is there a better way? > > function FixPlatformPath(PathIn: string): string; > begin > {$ifdef UNIX} > Result:= StringReplace(PathIn, '\', PathDelim, [rfReplaceAll]); > {$else} > Result:= StringReplace(PathIn, '/', PathDelim, [rfReplaceAll]); > {$endif} > end; > > This would apply to all functions where files are handled such as > reading config data, creating data files or reading data files etc... > > > -- > Bo Berglund > Developer in Sweden > > -- > _______________________________________________ > lazarus mailing list > lazarus@lists.lazarus-ide.org > https://lists.lazarus-ide.org/listinfo/lazarus >
-- _______________________________________________ lazarus mailing list lazarus@lists.lazarus-ide.org https://lists.lazarus-ide.org/listinfo/lazarus