Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Location of Saved Files

This thread is locked; no one can reply to it. rss feed Print
Location of Saved Files
inspiredevistate
Member #7,980
November 2006

A quick question...

I am trying to control where the user saves a file. For example, the user creates a bitmap and wants to save this bitmap.

I want the bitmap to be saved under the folder the program is run from under a folder called "Bitmaps"

Currently, I am only using save_bitmap();

I am thinking file_select_ex() may be what I need? But is there another way?

TeamTerradactyl
Member #7,733
September 2006
avatar

Usually, if you do not provide a path option for them, such as file_select_ex, then the user is forced to accept your path selections.

1) Prompt them for the "save to:" filename (not path)
2) Allow all characters as input except those that could be perceived as a "change path" character (/ or \\, etc.)
3) When they're done typing, you can do some extra stripping of the characters and ensure that the page that you specify, like SAVE_DIR, is the same that you will be saving the resulting BITMAP (or filename, or whatever) into. If it is, save as normal. Otherwise, strip off all "extra" characters.

Matthew Dalrymple
Member #7,922
October 2006
avatar

char* Savefilename;
Savefilename = "Bitmaps/hethisismyfirstbitmap.bmp";
save_bitmap(Savefilename, ...)

Just include the relative path in the filename section in save_bitmap(), that will store it in any directory you want.

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

inspiredevistate
Member #7,980
November 2006

Quote:

char* Savefilename;
Savefilename = "Bitmaps/hethisismyfirstbitmap.bmp";
save_bitmap(Savefilename, ...)

for some reason, it didn't create the BITMAP folder, I searched for it and could not find it... this is what i used

char *path;
/*allegro has been init and all that good stuff
and user picks Yes to save file*/
path = "Bitmaps\\testbmp.bmp";
save_bitmap(path, myBMP, pal);
/*exiting allegro, etc*/

LennyLen
Member #5,313
December 2004
avatar

Quote:

for some reason, it didn't create the BITMAP folder

You will have to do this yourself. If you're using gcc, there is the mkdir() function for creating directories.

inspiredevistate
Member #7,980
November 2006

Thanks! I've finally figured it out!

Thanks to all your help!!;D

TeamTerradactyl
Member #7,733
September 2006
avatar

You may also want to use '/' instead of '\\' for path separators: Windows will automatically convert these to the double-backslashes for you, and this makes it more cross-compatible with Linux/Mac.

Go to: