discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating file on Windows


From: Stefan Bidi
Subject: Re: Creating file on Windows
Date: Wed, 13 Apr 2011 08:27:42 -0500

On Tue, Apr 12, 2011 at 5:55 PM, Richard Frith-Macdonald <richard@tiptree.demon.co.uk> wrote:

On 12 Apr 2011, at 20:19, Stefan Bidi wrote:

> I have the following code on a Windows machine:
>
>       char buffer[3] = {'a', 'b', 'c'};
>       NSString *filename = @"/c/Analyzer Data/output.csv";
>       file = [NSFileHandle fileHandleForWritingAtPath: filename];
>       NSLog (@"%@", file);
>       [file writeData: [NSData dataWithBytes: buffer length: 3]];
>
> The file never gets created.  The directory C:\Analyzer Data\ exists and is writable by the user but -fileHandleForWritingPath: returns nil (per the NSLog).
>
> This machine has the latest stable Windows binary release.  Any suggestions?  I'm sure I'm missing something simple, just don't know what.

The path '/c/Analyzer Data/output.csv' is a relative path on the current drive ... if your current drive is C: then it's equivalent to the absolute path 'C:/c/Analyzer Data/output.csv'
Now, if 'C:/c/Analyzer Data/' does not exist, it can't create a file, and in any case it wouldn't create a file in 'C:/Analyzer Data/'

Thanks.  I didn't know I needed to specify C: at the beginning.
 
When working with paths, for portability, you should not hard-code paths ... rather you should use the API functions to obtain paths to standard logical locations and manipulate them by adding and removing path components.

Actually, now that you bring that up, I have what I think is a bug.  Whenever I use NSHomeDirectory() to find the user's home (in this case mine) I get $HOMEPATH and not $HOME.  Two problems here... $HOMEPATH is set to some network drive.  I don't know where Msys got this path from because I don't have it set anywhere on my Windows paths.  Secondly, $HOME is set to Msys's home dir (ie /home/$USERNAME), not Windows' home C:/Documents and Settings/$USERNAME.

Is all that clear?

I don't really have a problem with portability since this particular software will only be used on Windows machines.

Thanks

reply via email to

[Prev in Thread] Current Thread [Next in Thread]