Creating a file with FSpCreate

Ask a Question related to Mac Programming, Design and Development.

  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. Similar Questions and Discussions

    1. 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
    2. 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...
    3. 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...
    4. 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. ....
    5. 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...
  3. #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

  4. #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-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 ( 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

  5. #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-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 ( 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

Posting Permissions

  • You may not post new threads
  • You may 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