![]() |
creation of a file through programming????
hi all
I want to create a file(that may be .wav,AIFF,rtf or other) on mac system through programming. How i can do this. Thanks and regards |
Quote:
Are you a programmer? What programming language(s) do you want to use to do this? Where is the data for the file coming from? There is nothing special about creating a file on OS X - you would do it in the same way you would on any other OS. Again - please supply full details of what you are asking about. |
hi all
I am new to Mac Os. I want to create the file using C/C++ programming. I create the file using following code and the file created but i unable to open this file.This is a .AIFF file. FILE *fp; fp = fopen(Audio 1_01,"wb+"); fwrite(DataBuff,SizeToSave,1,fp); DataBuff buffer contains the raw contents of file. I have also created the resource fork file using File fp; fp = fopen(._Audio 1_01,"wb+"); fwrite(ResourceBuff,SizeToSave,1,fp); ResourceBuff buffer contains the resource raw data of file. When i open the created file using the hex editor then I see File Type/Creator is empty. But i don't know how to deal with this resource fork file creation. How the created resource fork file linked to its data fork file. When i open the created file using the hex editor then I see File Type/Creator is empty. If any body have idea then plz help me. Thanx in advance |
You should not be creating a resource fork for a file to be used with OS X since resource forks are not recommended anymore.
Just concentrate on creating the file (the data fork). After that is working, then worry about setting the file creator and type. You probably need to read Apple's documentation on the Carbon File manager: http://developer.apple.com/documenta...ger/index.html |
hi all
How i can set the file type and creator information to the created file or i have to create file by supplying these informations. Where i found the information and documents about the setting of file type and creator to a file. |
>How i can set the file type and creator information to the created file
-- Below is a quick and dirty script to do it... untested on OS X, but should work. Peter B. -- Off Topic to an OS X Hints Moderator: At least one pre-X browser (IE 5.1.7) doesn't appear to handle the <pre> tag (?) for quoting code. The code blocks end up empty boxes... though don't know if it matters to you since you're targeting the X crowd anyway... PB ----- on open these_items repeat with this_item in these_items tell application "Finder" set the_name to the name of this_item try set file_type to the file type of this_item on error set file_type to "" end try try set creator_type to the creator type of this_item on error set creator_type to "" end try display dialog "Set The File Type For..." & return & return & ¬ "\"" & the_name & "\"" & return & return & ¬ "Current File Type: " & file_type & return & return default answer "" set new_file_type to text returned of the result display dialog "Set The Creator Type For..." & return & return & ¬ "\"" & the_name & "\"" & return & return & ¬ "Current Creator Type: " & creator_type & return & return default answer "" set new_creator_type to text returned of the result set the file type of this_item to new_file_type set the creator type of this_item to new_creator_type end tell end repeat end open -------------------- ----------------------------------- |
Quote:
But anyway, I don't think anyone here really worries about support of any such old browser - on any version of any OS. For example, we don't really worry if something doesn't work in IE on OS X either - all versions of IE are so old and unsupported by Microsoft that it is strongly recommended that you avoid using them - they have several unpatched security holes. |
Quote:
But I think there is no problem in calling Cocoa routines from C++ - you just wrap them in a C++ method. So you could use the Cocoa methods of NSFileManager. By the ay, you should already have all this documentation on your hard disk - since it gets installed as part of Apple's developer tools. You seem to be trying to work on a project without the benefit of previous Mac training or even a book on Macintosh programming. That would be rather frustrating. I strongly recommend you stop working on your project and just sit down with an appropriate book and learn the basics. And I think you might get more help if you posted to a dedicated programming mailing list instead of these forums - your queries would reach many more developers with experience with the sorts of things you are doing. For example, here's the page for the Carbon-dev list: http://lists.apple.com/mailman/listinfo/carbon-dev |
As I earlier told that i am a new programmer on mac. I have knowledge of Mac(HFS and HFS+) file system. I have written a small programe in my pc(using visual c++) to recover files of a crashed mac HDD is connected to pc then my program is able to recover both data fork and resource fork. If we transfer both data fork and rosource fork of a file to mac machine the file run perfectly.
Now i am writing the same program on mac machine. I know the location of both data fork and resource fork . But my problem is how to associate them with each other. I have already discuss how i am writting both the files(data fork and resource fork). if any body have some idea then plz help me. Thanks and regards |
Quote:
cp resource_fork_filename data_fork_filename/..namedfork/rsrc If you want to do this from inside a program, you could use 'system()' |
hi all
I am still not able to associate both resource fork and data fork. I have also tried the following command cp resource_fork_filename data_fork_filename/..namedfork/rsrc I want to do this programmically how i can use the 'System()' Thanks and Regards |
Quote:
man system in a Terminal window and read carefully. Then try a small test program that just does 'system("ls");' and run it to check that it works. Build up from there. |
hi all
How i can use FSOpenFork() and WriteFork() of File Manager in my simple C program. Which header file i have to include in my program. Thanks and Regards |
There is no substitute for reading the documentation.
|
Hi all
Can i create the data fork and resource fork through C Programming. If yes then plz help me by giving example code how i can create a simple file. Thanks and Regards |
Hi all
I have read *File Manager reference document which contains all the information on opening/closing , reading/writing data fork and resource fork. If i use the following API for creating a file:- extern OSErr HOpenDF( * short * * * * * * *vRefNum, * long * * * * * * * dirID, * ConstStr255Param * fileName, * SInt8 * * * * * * *permission, * short * * * * * * *refNum) * I have included the path of "Files.h". ld: form3.o illegal reference to symbol: _FSpCreate defined in indirectly referenced dynamic library /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/CarbonCore What should i have to do? Thanks and Regards |
Path of a Lib file???
I have to use the following API
extern OSErr FSpCreate( const FSSpec * spec, OSType creator, OSType fileType, ScriptCode scriptTag ) I have declared the following FSSpec *spec; spec->vRefNum=0; spec->parID=2; unsigned char filename[64]="Aman"; spec->name=filename; OSType creator="PTul"; OSType fileType="Sd2f"; ScriptCode scriptTag="smSystemScript"; I have include the path Of "Files.h" in Project Settings--Includepath There is no error upto this point But when i call the FSpCreate(spec,creator,fileType,scriptTag); then there is following error :- ld: form3.o illegal reference to symbol: _FSpCreate defined in indirectly referenced dynamic library /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/CarbonCore I have to include the CarbonLib 1.0 but this lib file available in more than one folder.Which Path should I have to include? Plz help me. Thanks and Regards |
Hi all
I have included the lib file and now when i compiling my application there is no error but still file is not created.I want to know about the FSSpec structure. I have passed the following values to this structure spec.vRefNum=0; spec.parID=4029; unsigned char filename[64]="Aman"; spec.name=filename; FSpCreate(&spec, 'ttxt', 'TEXT', smSystemScript); * I want to create file on root . What i should pass to parId and vRefNum?? How i can get the Volume reference number. Thanks and Regards |
Creation of a file using FSpCreate()??
Hi
I am using the function FSMakeFSSpec to get a valid FSSpec but still file is not created. I have made this program in QT Programming for Mac(C++ GUI programming kit by trolltech.org). I am trying to make a text file using programming. I have used the following code in my application:- OSErr err; FSSpec spec; err=FSMakeFSSpec(0,0,"/unique/hello.txt",&spec); if(err == fnfErr) QMessageBox::information(0, "message","hiiiiiiiiii"); FSpCreate(&spec, 'CWIE', 'TEXT', smSystemScript); I have included the following Libs in my application:- LIBS+=/System/Library/Frameworks/Carbon.framework/Carbon LIBS+=/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation I have included the "Files.h" in my project settings:- /System/Library/Frameworks/CoreServices.framework/CarbonCore.framework/Versions/A/Headers/Files.h When i am compiling the program there is no error but file is not created. Plz help me where i am wrong?? Thanks and Regards |
You don't seem to be checking the return value (error code) from FSpCreate.
I'm guessing that there is an error that is preventing the creation of the file. |
Quote:
hi In my code i have given the MessageBox but this message box is not appeared when i run the program. There is an error in FSMakeFSSpec() function. But i am still not able to get the error. Thanks and Regards |
hi
I have checked the "err" in my code I have got the result code "-37" Which represent the "Bad filename or volume name". I have given a full path of existing directory named "unique" on root and want to create a hello.txt file in that directory. Where i am wrong plz help me. Thanks and Regards |
I have no experience with this, but googling for:
FSMakeFSSpec example gave several useful pages, including this one: http://www.macosx.com/forums/archive...p/t-73850.html that shows that the problem is that the file path needs to be specified using traditional Macintosh conventions, not Unix conventions. E.g. the folder separator is ":" instead of "/". |
Hi
Actually I am writting a program to recover a file from a crashed Apple Macintosh Disk having HFS or HFS+ file system. I have enough knowledge of HFS and HFS+ file system. All is well in my program now i am on saving part a file. I know Where the Data Fork and Resource Fork sectors or clusters of a file lies on the Hard Disk. I am able to raw read those particular sectors for crashed hard disk. I want to Create a file and then open the Data Fork of created file and Write the data fork data from crashed hard disk and then open the Resource Fork of created file and Write the resource fork data from the crashed hard disk and then close the file. I have made this program in QT Programming for Mac(C++ GUI programming kit by trolltech.org). I am trying to make a text file using programming. I have used the following code in my application:- OSErr err; FSSpec spec; err=FSMakeFSSpec(0,0,":unique:hello.txt",&spec); if(err != fnfErr) { //Display message and exit } FSpCreate(&spec, 'CWIE', 'TEXT', smSystemScript); I have included the following Libs in my application:- LIBS+=/System/Library/Frameworks/Carbon.framework/Carbon LIBS+=/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation I have included the "Files.h" in my project settings:- /System/Library/Frameworks/CoreServices.framework/CarbonCore.framework/Versions/A/Headers/Files.h When i am compiling the program there is no error but file is not created. I have checked the "err" in my code I have got the result code "-35" Which represent the "Bad volume name". I have given a full path of existing directory named "unique" on root and want to create a hello.txt file in that directory. Where i am wrong plz help me. How i can use FSMakeFSRefUnicode and FSRefs (instead of FSSpecs). Plz give example code if any. Thanks and Regards |
Quote:
I have no example code to provide (having never done this - I have only programmed in Cocoa and never dealt with resource forks) but I see in that web page I referred to above that people are recommending the Apple-supplied example file "MoreFiles". This is on the Apple developer web site, in the section for sample code. |
Hi all
I have search the carbon mailing archive which suggest me to create file using the FSCreateFileUnicode() I have studied this fuction but i have got little bit confused. Plz help by giving some code example to create file using FSCreateFileUnicode(). Thanks and Regards |
It is quite unlikely that you will get the sort of example code you are looking for here. You should search Apple's sample code pages and use Google to search for the specific functions you are looking for - that would be a much more fruitful way.
|
| All times are GMT -5. The time now is 06:02 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.