Ask a Question related to Mac Programming, Design and Development.
-
Mike H. #1
Creating a file with FSpCreate
This is probably a very stupid question, but I can't seem to get this to
work. I had a very strong background programming in Classic...
I want to create a file in a certain directory, /Library/Preferences/Folder.
It should go on the main volume.
I got a copy of MoreFilesX, and tried the following:
UInt8 thePath[1024];
memset(thePath, 0, sizeof(thePath));
strcpy((char*)thePath, "/Library/Preferences/MyFolder/test.txt");
myErr = FSPathMakeFSSpec(
thePath,
&prefSpec,
&isDirectory);
If ( myErr == fnfErr ) //file doesn't exist
myErr = FSpCreate(&prefSpec,kMyCreatorCode,kMyTextType,smS ystemScript);
However, this clearly doesn't work, giving me a volume not found error
(-35). I tried specifying the volume directly, by noting kOnSystemDisk for
the vRefNum in prefSpec, but no luck.
So I tried again. This time I figured that if I specify the volume type
(which I can get from FindFolder) then it should work. I put the following
code in front of the FSpCreate call:
myErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder,
&myVRef, &myDirIDs);
if (myErr == noErr)
prefSpec.vRefNum = myVRef;
Now I get an error -37.
I realize that there are all sorts of different domains---and that I'm
probably a major idiot. Any ideas?
Thanks,
Mike Hunson
Mike H. Guest
-
Creating a File List
Hy, I'm trying to create a extension that has a drop-down list of all the documents of a certain document type, how can I do this. Thanks -
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 config file.
TY to anyone reading about my problem. What I am trying to do is what I have seen many places where there are Flash templates. There is always a... -
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. .... -
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... -
Frederick Cheung #2
Re: Creating a file with FSpCreate
On Fri, 26 Sep 2003, Mike H. wrote:
> This is probably a very stupid question, but I can't seem to get this to
> work. I had a very strong background programming in Classic...
>
> I want to create a file in a certain directory, /Library/Preferences/Folder.
> It should go on the main volume.
>
> I got a copy of MoreFilesX, and tried the following:
>
> UInt8 thePath[1024];
> memset(thePath, 0, sizeof(thePath));
> strcpy((char*)thePath, "/Library/Preferences/MyFolder/test.txt");
>
> myErr = FSPathMakeFSSpec(
> thePath,
> &prefSpec,
> &isDirectory);If you look at the code in the code, you will they that it first makes an>
> If ( myErr == fnfErr ) //file doesn't exist
> myErr = FSpCreate(&prefSpec,kMyCreatorCode,kMyTextType,smS ystemScript);
>
> However, this clearly doesn't work, giving me a volume not found error
> (-35). I tried specifying the volume directly, by noting kOnSystemDisk for
> the vRefNum in prefSpec, but no luck.
fsref for the path, then gets the fsspec. Since you can't have an FSRef
for a function that doesn't exist, you won't get a valid FSSpecYou should use the dirID and the volume number given to you by findfolder>
> So I tried again. This time I figured that if I specify the volume type
> (which I can get from FindFolder) then it should work. I put the following
> code in front of the FSpCreate call:
>
> myErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder,
> &myVRef, &myDirIDs);
>
> if (myErr == noErr)
> prefSpec.vRefNum = myVRef;
>
> Now I get an error -37.
to make your FSSpec.
FSMakeFSSpec(myVRef,myDirIDs,"\pMyFolder:test.txt" ,&prefSpec);
If you want to use unicode filenames you should ditch the fsspecs and use
fsrefs/
Fred>
> I realize that there are all sorts of different domains---and that I'm
> probably a major idiot. Any ideas?
>
> Thanks,
>
> Mike Hunson
>
>Frederick Cheung Guest
-
Mike H. #3
Re: Creating a file with FSpCreate
I think you misunderstood---I was just trying to use FindFolder in order to
get the right volume reference.
I actually want to put the file in a different folder, that I have specified
via a pathname.
-Mike H.
in article
[email]Pine.LNX.4.44.0309261731350.32470-100000@kern.srcf.societies.cam.ac.uk[/email],
Frederick Cheung at [email]fglc2@srcf.DUH.ucam.org[/email] wrote on 9/26/03 12:40 PM:
> On Fri, 26 Sep 2003, Mike H. wrote:
>>>> This is probably a very stupid question, but I can't seem to get this to
>> work. I had a very strong background programming in Classic...
>>
>> I want to create a file in a certain directory, /Library/Preferences/Folder.
>> It should go on the main volume.
>>
>> I got a copy of MoreFilesX, and tried the following:
>>
>> UInt8 thePath[1024];
>> memset(thePath, 0, sizeof(thePath));
>> strcpy((char*)thePath, "/Library/Preferences/MyFolder/test.txt");
>>
>> myErr = FSPathMakeFSSpec(
>> thePath,
>> &prefSpec,
>> &isDirectory);> If you look at the code in the code, you will they that it first makes an>>
>> If ( myErr == fnfErr ) //file doesn't exist
>> myErr = FSpCreate(&prefSpec,kMyCreatorCode,kMyTextType,smS ystemScript);
>>
>> However, this clearly doesn't work, giving me a volume not found error
>> (-35). I tried specifying the volume directly, by noting kOnSystemDisk for
>> the vRefNum in prefSpec, but no luck.
> fsref for the path, then gets the fsspec. Since you can't have an FSRef
> for a function that doesn't exist, you won't get a valid FSSpec> You should use the dirID and the volume number given to you by findfolder>>
>> So I tried again. This time I figured that if I specify the volume type
>> (which I can get from FindFolder) then it should work. I put the following
>> code in front of the FSpCreate call:
>>
>> myErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder,
>> &myVRef, &myDirIDs);
>>
>> if (myErr == noErr)
>> prefSpec.vRefNum = myVRef;
>>
>> Now I get an error -37.
> to make your FSSpec.
> FSMakeFSSpec(myVRef,myDirIDs,"\pMyFolder:test.txt" ,&prefSpec);
> If you want to use unicode filenames you should ditch the fsspecs and use
> fsrefs/
>
> Fred>>>
>> I realize that there are all sorts of different domains---and that I'm
>> probably a major idiot. Any ideas?
>>
>> Thanks,
>>
>> Mike Hunson
>>
>>
Mike H. Guest
-
Frederick Cheung #4
Re: Creating a file with FSpCreate
On Fri, 26 Sep 2003, Mike H. wrote:
POSIX style paths specify files/folders uniquely, you don't need to get a> I think you misunderstood---I was just trying to use FindFolder in order to
> get the right volume reference.
>
> I actually want to put the file in a different folder, that I have specified
> via a pathname.
volume reference. I believe your problem is that FSPathMakeFSSpec will
not work if the file the path points at does not exist (because of the
internal use of FSRefs.
Fred
>
> -Mike H.
>
> in article
> [email]Pine.LNX.4.44.0309261731350.32470-100000@kern.srcf.societies.cam.ac.uk[/email],
> Frederick Cheung at [email]fglc2@srcf.DUH.ucam.org[/email] wrote on 9/26/03 12:40 PM:
>>> > On Fri, 26 Sep 2003, Mike H. wrote:
> >> >> >> This is probably a very stupid question, but I can't seem to get this to
> >> work. I had a very strong background programming in Classic...
> >>
> >> I want to create a file in a certain directory, /Library/Preferences/Folder.
> >> It should go on the main volume.
> >>
> >> I got a copy of MoreFilesX, and tried the following:
> >>
> >> UInt8 thePath[1024];
> >> memset(thePath, 0, sizeof(thePath));
> >> strcpy((char*)thePath, "/Library/Preferences/MyFolder/test.txt");
> >>
> >> myErr = FSPathMakeFSSpec(
> >> thePath,
> >> &prefSpec,
> >> &isDirectory);> > If you look at the code in the code, you will they that it first makes an> >>
> >> If ( myErr == fnfErr ) //file doesn't exist
> >> myErr = FSpCreate(&prefSpec,kMyCreatorCode,kMyTextType,smS ystemScript);
> >>
> >> However, this clearly doesn't work, giving me a volume not found error
> >> (-35). I tried specifying the volume directly, by noting kOnSystemDisk for
> >> the vRefNum in prefSpec, but no luck.
> > fsref for the path, then gets the fsspec. Since you can't have an FSRef
> > for a function that doesn't exist, you won't get a valid FSSpec> > You should use the dirID and the volume number given to you by findfolder> >>
> >> So I tried again. This time I figured that if I specify the volume type
> >> (which I can get from FindFolder) then it should work. I put the following
> >> code in front of the FSpCreate call:
> >>
> >> myErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder,
> >> &myVRef, &myDirIDs);
> >>
> >> if (myErr == noErr)
> >> prefSpec.vRefNum = myVRef;
> >>
> >> Now I get an error -37.
> > to make your FSSpec.
> > FSMakeFSSpec(myVRef,myDirIDs,"\pMyFolder:test.txt" ,&prefSpec);
> > If you want to use unicode filenames you should ditch the fsspecs and use
> > fsrefs/
> >
> > Fred> >> >>
> >> I realize that there are all sorts of different domains---and that I'm
> >> probably a major idiot. Any ideas?
> >>
> >> Thanks,
> >>
> >> Mike Hunson
> >>
> >>
>
>Frederick Cheung Guest



Reply With Quote

