[futurebasic] Re: [FB] Status: FB's File I/O statement update ( i.e. conversion to 64-bit ) still in-progress

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2017 : Group Archive : Group : All Groups

From: Bernie <bernie.fblist@...>
Date: Mon, 27 Feb 2017 23:09:30 +0000
Mark wrote:
> 
> In one part of my data-acquisition app, users can specify a ‘base’ file name (using FILES$) .  Then the program gathers and saves data in a sequence of files, with the sequence number appended to the base file name (e.g., ‘base 1’, ‘base 2’, ‘base 3’…..).   I could do that using FSrefs because they required a file name in order to create a new file with the ‘OPEN’ statement.   
> 
> How could this be done using CFURLrefs?   I’d like the change to be transparent to users:  they would spcifiy a base file name (and location) with FILES$.  But for each save, a new file name has to be used.   How does one change the CFURLref so that each successive save has a new name (the sequence number appended to the base file name)?
> 
> I poked aorund in the Tlbx CFURL.incl header but there was nothing obvious (to me).
> 


OTTOMH:

// ---------------
include "Util_FileDirectory.incl"

local fn FileURLCreate( dirURL as CFURLRef, basename as CFStringRef ) as CFURLRef
'~'1
dim as CFURLRef      fileURL
dim as CFStringRef   filename
dim as UInt32        fileID : fileID = 1
dim as Boolean       ok : ok = _false

do
filename = fn CFStringCreateWithFormat( _kCFAllocatorDefault, NULL, @"%@ %ld", basename, fileID )
fileURL = fn CFURLCreateCopyAppendingPathComponent( _kCFAllocatorDefault, dirURL, filename, _false )
CFRelease( filename )
if ( fn FD_ObjectExistsCFURL( fileURL ) )
CFRelease( fileURL )
fileID++
else
ok = _true
end if
until ( ok )
end fn = fileURL

void local fn SaveAction
'~'1
dim as CFURLRef      fileURL, dirURL
dim as CFStringRef   basename

if ( files$( _CFURLRefSave, "Save", "base", @fileURL ) )
basename = fn CFURLCopyLastPathComponent( fileURL )
dirURL = fn CFURLCreateCopyDeletingLastPathComponent( _kCFAllocatorDefault, fileURL )
CFRelease( fileURL )

fileURL = fn FileURLCreate( dirURL, basename )

open "O",1,@fileURL
close

CFRelease( fileURL )
CFRelease( basename )
CFRelease( dirURL )
end if
end fn

void local fn DoMenu
'~'1
if ( menu(_menuID) == 1 && menu(_itemID) == 1 ) then fn SaveAction()
end fn

menu 1,0,1,@"File"
menu 1,1,1,@"Save.../S"

on menu fn DoMenu

RunApplicationEventLoop()
// ---------------