[futurebasic] Re: [FB] file paths

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2008 : Group Archive : Group : All Groups

From: Robert Covington <artlythere@...>
Date: Thu, 17 Jan 2008 17:10:24 -0500
That prior post just some sample code, needs tailoring to the  
situation, it's not set out as a working program. :)

Here's a working mini-program which should not kill anything by  
accident. :) If you wish to keep that mySpec around for future use,  
you can make an alias, and save that to a prefs file, reload later.

dim fname$
dim mySpec as FSSpec

include "Util_Files.incl" // For the USR Functions
// Save
def open "TEXTR*ch" // Text , BBEdit app
fName$ = Files$(_FSSpecSave,"Choose a filename to  
save...","Untitled",mySpec)
long if len(fName$)

// this one overwrites
/*Open "O",1,@mySpec
Print #1,"Here we are"
Close #1*/

// this one appends
Open "A",1,@mySpec
Print #1,"Here we are again (and again if we reopen)"
Close #1

// Automatic writing
long if USR FSFileExists(mySpec)
Open "A",1,@mySpec
Print #1,"We existed. We wrote. We left."
Close #1
end if

xelse
beep // user canceled
end if





On Jan 17, 2008, at 5:00 PM, Robert Covington wrote:

> If you are using the  Files$ dialog to get the user's choice, it  
> should ask if you wish to replace it when they choose the same one?
>
> For knowing otherwise, if you have a known, FSSpec,  or Path, or  
> the various components of non-fspec'ness (deprecated working  
> directory numbert/etc) you can use:
>
> exists =  USR FSFileExists(fspec) or
> exists =  USR FileExists(blah blah blah)
>
> If you wish to append to the end of a file, add to it, and not  
> overwrite it, you can use the Open "A" method. Open "O" will  
> overwrite things.
>
> FB's file methods are behind the times for filtering and such via  
> the typelist these days, you usually need to use a nav services  
> callback to get best results, but here's the general methods.
>
> // User has chosen File Menu Open or Save
> dim fname$
> dim mySpec as FSSpec
>
> // Open (Text files in this case, for everything... use "" )
> fName$ = Files$(_FSSpecOpenPreview,"TEXT", "Choose a file...",mySpec)
>
> // Save
> Def Open "TEXTCRTR" // Text file type, your app's creator code (can  
> get via Apple)
> fName$ = Files$(_FSSpecSave,"Choose a filename to  
> save...","Untitled",mySpec)
>
> Open "O",1,@mySpec
> Print #1,"Here we are"
> Close #1
>
> //Or:
>
> Open "A",1,@mySpec
> Print #1,"Here we are again (and again if we reopen)"
> Close #1
>
>
> Robert
>
> On Jan 17, 2008, at 4:32 PM, Robert wrote:
>
>> Hi group
>>
>> I am getting great success with many things but I am seriously  
>> hung up on two issues.
>>
>> I have written a program that creates a file and opens it and then  
>> I print some text and numbers to the file and then it closes.  
>> Works great but if the file exists it is overwritten. Is there a  
>> method of checking for the existence of the file you are about to  
>> open so that the user can be asked if the overwrite is ok or to  
>> bail out?
>>
>> I can open file menus but all I can get out of these  is a file  
>> name, or directory name but not a complete path name so my output  
>> files are created only in the directory from which the program is  
>> run.
>>
>> Aw gee, guys please don't tell me it takes a long program segment  
>> to do this lol.
>>
>> And big thanks for putting up with my many questions, I am  
>> spending a lot of effort to figure out things by myself, honest.
>>
>> Robert
>>
>> --
>> To unsubscribe, send ANY message to: futurebasic- 
>> unsubscribe@...
>>
>
> --
> To unsubscribe, send ANY message to: futurebasic- 
> unsubscribe@...
>