[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: File path issue on Win32 only
From: |
Richard Frith-Macdonald |
Subject: |
Re: File path issue on Win32 only |
Date: |
Tue, 27 Feb 2007 12:03:45 +0000 |
On 27 Feb 2007, at 11:34, Michael Hopkins wrote:
Sorry to bug you directly but I believe you are the Windows guru
for GNUstep and we have a Windows-only question which has not yet
been answered on the public lists and which I think must have a
simple answer.
Sorry I didn't reply to your earlier messages ... I've been away at
FOSDEM and rather busy (and mostly without the ability to send emails).
In a Foundation tool, we initialise an object with a file in the
path where the executable resides:
[[Experiment alloc] initFromFile:@"test.gpe"];
It uses this code internally:
-(Experiment *) initFromFile:(NSString *) filePath
{
NSString* file_off_disk = [NSString
stringWithContentsOfFile:filePath];
That all looks fine.
If the path is simply 'test.gpe' I'm surprised that anything could
fail ... but I expect you already tried logging the value of filePath
immediately before the call to stringWithContentsOfFile: to check
that nothing has been done to modify the original path.
This works fine on OS X and Linux, but gives the following error on
Win32:
2007-02-23 13:46:39.987 test.exe[1300] File NSData.m: 167. In
readContentsOfFile() attempt failed - The filename, directory name,
or volume label syntax is incorrect.
I don't think that particular error message exists in either the
current release or in subversion trunk ... so my guess is that you
are using an older version, so perhaps there is some old bug causing
the trouble (though I can't remember anything likely).
I realise you may be using an older release of the software because
no easy windows installer has been provided for the current
release ... hopefully we can change that in a day or two (I've just
been informed that a new installer is ready, so we just need to get
it onto the server ready for download).
Tried this as an attempted quick fix but it doesn't help:
[[Experiment alloc] initFromFile:[@"test.gpe"
stringByStandardizingPath]];
Is there an object and/or method available in Foundation that lets
me easily convert local filenames to global ones in a form that all
platforms will understand?
The recommendation for portability is to only pass around relative
paths, since absolute path names on windows and unix are
incompatible. You can use standard functions from NSPathUtilities.h
and paths returned from NSBundle etc to find the base paths for your
current platform, then use stringByAppendingPathComponent: to append
the relative paths to those base paths. That's really the only way
to be sure that code which passes paths around is portable.
- Re: File path issue on Win32 only,
Richard Frith-Macdonald <=