Ask a Question related to Mac Programming, Design and Development.
-
Stéphane Vaxelaire #1
File creating problem
Hello,
I'm trying to test if a file exists and if not I try to create it in
order to open it for writing.
So I first use FSpGetFInfo to check if the file exists, then if
iErr==fnfErr I try to create the file.
In my example below cpath="/Users/surfdargent/test" and is an absolute
path.
My first problem : apparently even if the file exists (I just create
it with 'vi') FSpGetFInfo returns fnfErr and then my prog tries to
create the file.
But now FSpCreate return -37 (bdNamErr) which should mean something
like bad filename or bad volume.
Did I do something wrong ?
Another thing : I haven't found any document explaining the creator
and filetype stuff yet... could someone quickly explain what
parameters I need to pass to FSpCreate for a jpeg file ?
I have no experience in manipulating FS under MacOS X... any help is
appreciated. Regards.
Here is my piece of code :
cerr<<"Trying to open file : "<<cpath<<endl;
FSMakeFSSpec( 0, 0, cpath, &spec);
short fp;
long nbwritten;
// Create file if doesn't exist
if( (iErr = FSpGetFInfo( &spec, &finfo)) != noErr)
{
// If file was not found we create it
if( iErr == fnfErr)
{
iErr = FSpCreate( &spec, 'JPEG', 'JPEG', smSystemScript);
if( iErr)
DoError( iErr, "FSpCreate failed.");
}
else
DoError( iErr, "FSpGetFInfo failed.");
}
// Open for writing
iErr = FSpOpenDF( &spec, fsWrPerm, &fp);
if (iErr)
DoError( iErr, "FSpOpenDF failed.");
iErr = FSpOpenRF( &spec, fsWrPerm, &fp);
if (iErr)
DoError( iErr, "FSpOpenRF failed.");
// Write the jpeg data
iErr = FSWrite( fp, &nbwritten, jpeg_data);
if (iErr)
DoError( iErr, "FSWrite failed.");
// Close the file
FSClose( fp);
Stéphane Vaxelaire Guest
-
problem in binding xml file data to datagrid xml file isgenerated through JSP file
problem it that i am creating xml file using JSP file and i want to bind DataGrid with xml file data that is created using JSP but it will not Bind... -
Problem creating PDF file using Acrobat PDFWriter PDFFileName
Good morning. I'm having a problem that a think may be related to Acrobat 6.0 as I had this working with 5.0. Bascially, I am setting the... -
Problem creating link to a file
Hi, I'm using Acrobat Professional 6.0 and have the need to often editing PDFs which are on network shares, creating links to other files which are... -
Creating PDF file
I am new to Adobe usage and am trying to create a PDF file that will need to be created from word documents as well as a powerpoint program. This... -
creating a new file
I need to write a script which when run will create a new text file depending if there is another text file which contains certain string e.g. .... -
Tom Dowdy #2
Re: File creating problem
In article <bca37bb1.0307240435.179818e@posting.google.com> ,
[email]surfdargent@free.fr[/email] (Stéphane Vaxelaire) wrote:
fnfErr will also be returned if you are incorrectly specifying the path> I'm trying to test if a file exists and if not I try to create it in
> order to open it for writing.
> So I first use FSpGetFInfo to check if the file exists, then if
> iErr==fnfErr I try to create the file.
> In my example below cpath="/Users/surfdargent/test" and is an absolute
> path.
> My first problem : apparently even if the file exists (I just create
> it with 'vi') FSpGetFInfo returns fnfErr and then my prog tries to
> create the file.
> But now FSpCreate return -37 (bdNamErr) which should mean something
> like bad filename or bad volume.
>
> Did I do something wrong ?
or incorrectly converting it into an FSSpec.
Similarlly, if this spec is incorrect, you'll get an "bad name error"
when attempting to create it.
Your path is a Unix-style path, which is invalid for calls into the
Carbon file manager. I recommend MoreFiles.c and example code on
Apple's web site for more information on how to handle absolute paths.
Tom Dowdy Guest
-
Frederick Cheung #3
Re: File creating problem
On 24 Jul 2003, Stéphane Vaxelaire wrote:
Firstly, when you call FSMakeFSSpec, it will return noErr if the> Hello,
>
> I'm trying to test if a file exists and if not I try to create it in
> order to open it for writing.
> So I first use FSpGetFInfo to check if the file exists, then if
> iErr==fnfErr I try to create the file.
> In my example below cpath="/Users/surfdargent/test" and is an absolute
> path.
> My first problem : apparently even if the file exists (I just create
> it with 'vi') FSpGetFInfo returns fnfErr and then my prog tries to
> create the file.
file/folder you are specifying exists, and fnfErr if all the elements of
the path exist, but not the actual file.
Secondly, the path separator used with HFS APIs is ':', not '/'
Lastly using 0 for dirID and vRefNum does not mean start from the root of
the disk, it means use the applications default directory, which is
usually the folder the application is in (unless you've changed it), if
your app is bundled i can't rmemember if you get the folder containing the
bundle or the one containing the executable.
You should probably be looking at the CFURLRef functions, or FSPathMakeRef
(which makes FSRefs).
Fred
Frederick Cheung Guest
-
Miro Jurisic #4
Re: File creating problem
In article
<Pine.LNX.4.44.0307242134460.15938-100000@kern.srcf.societies.cam.ac.uk>,
Frederick Cheung <fglc2@srcf.DUH.ucam.org> wrote:
If the path is absolute (i.e. starts with a non-':' and contains a ':') then it> Lastly using 0 for dirID and vRefNum does not mean start from the root of
> the disk, it means use the applications default directory, which is
> usually the folder the application is in (unless you've changed it), if
> your app is bundled i can't rmemember if you get the folder containing the
> bundle or the one containing the executable.
overrides any volref/dirid.
meeroh
Miro Jurisic Guest



Reply With Quote

