[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Creating file on Windows
From: |
Richard Frith-Macdonald |
Subject: |
Re: Creating file on Windows |
Date: |
Tue, 12 Apr 2011 23:55:11 +0100 |
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/'
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.