[futurebasic] Re: [FB] open file

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2012 : Group Archive : Group : All Groups

From: Bernie <fblist.bw@...>
Date: Thu, 9 Aug 2012 21:41:54 +0100
Ted wrote:

> On 9 Aug, 2012, at 9:16 AM, Bernie wrote:
> 
>> I'd skip FSSpec and FSRef and go straight to url. This example looks for and opens a file named "Colors" in the application folder.
>> '---------------
>> include "ConsoleWindow"
>> include "Util_FileDirectory.incl"
>> 
>> dim as CFURLRef      appDirUrl, fileUrl
>> dim as CFStringRef   fileName
>> dim as OSStatus      err
>> 
>> fileName = @"Colors"
>> err = fn FD_ApplicationDirectoryCreateCFURL( @appDirUrl )
> 
> Some of us in third world countries, with pedal-powered Macs and English as a third language, are having a bit of trouble with this... Does the line above create a URL for the app folder - and the app folder alone? Is there summat like that for any other particular folder (Documents, etc)? For ANY folder in particular? 

fn FD_SpecialDirectoryCreateCFURL( _kUserDomain, _kDocumentsFolderType, @url )
fn FD_SpecialDirectoryCreateCFURL( _kUserDomain, _kDesktopFolderType, @url )
fn FD_SpecialDirectoryCreateCFURL( _kUserDomain, _kPreferencesFolderType, @url )
fn FD_SpecialDirectoryCreateCFURL( _kUserDomain, _kApplicationsFolderType, @url )
…..

> What are these FD_ ... things?

A set of utility functions for handling files and directories. See Util_FileDirectory.incl in Headers.

> And why does...
> 
>> if ( err == _noErr )
>> fileUrl = fn CFURLCreateCopyAppendingPathComponent( _kCFAllocatorDefault, appDirUrl, fileName, _false )
> 
>> if ( fileUrl != NULL )
>> if ( fn FD_ObjectExistsCFURL( fileUrl ) )
>> open "I", 1, @fileUrl
>> // do something
>> print "File opened"
>> close 1
> 
> xelse print "No object"
> 
>> end if
>> CFRelease( fileUrl )
> xelse
> print File URL is nul"
>> end if
>> CFRelease( appDirUrl )
>> end if
>> '---------------
> 
> ... say "No Object" when ...
> 
> <Screen shot 2012-08-09 at 9 Aug, 4.18.43 PM.png>
> 

It looks for the file in the application folder (the folder containing the app), not necessarily the Applications folder.