Professional Web Applications Themes

Creating a file with FSpCreate - Mac Programming

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 ...

  1. #1

    Default 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

  2. #2

    Default 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 ( 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.
    If you look at the code in the code, you will they that it first makes an
    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
    >
    > 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.
    You should use the dirID and the volume number given to you by findfolder
    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

  3. #3

    Default 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-100000kern.srcf.societies.cam.ac.uk[/email],
    Frederick Cheung at [email]fglc2srcf.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 ( 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.
    > If you look at the code in the code, you will they that it first makes an
    > 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
    >>
    >> 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.
    > You should use the dirID and the volume number given to you by findfolder
    > 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

  4. #4

    Default Re: Creating a file with FSpCreate

    On Fri, 26 Sep 2003, Mike H. wrote:
    > 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.
    POSIX style paths specify files/folders uniquely, you don't need to get a
    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-100000kern.srcf.societies.cam.ac.uk[/email],
    > Frederick Cheung at [email]fglc2srcf.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 ( 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.
    > > If you look at the code in the code, you will they that it first makes an
    > > 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
    > >>
    > >> 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.
    > > You should use the dirID and the volume number given to you by findfolder
    > > 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

Similar Threads

  1. Creating multiple file into one PDF through VBA
    By meanmel in forum Adobe Acrobat SDK
    Replies: 0
    Last Post: September 3rd, 06:38 PM
  2. Creating PDF file
    By PT_M.A._Rosenberg@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 0
    Last Post: April 28th, 02:09 PM
  3. Creating Text File
    By Erik in forum ASP
    Replies: 5
    Last Post: September 14th, 10:16 PM
  4. creating a new file
    By MJS in forum PERL Miscellaneous
    Replies: 5
    Last Post: August 12th, 05:13 PM
  5. File creating problem
    By Stéphane Vaxelaire in forum Mac Programming
    Replies: 3
    Last Post: July 25th, 02:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139