How to save a file in curent directory?

This is a discussion on How to save a file in curent directory? within the C Programming forums, part of the General Programming Boards category; hi guys ... i wonder how is it possible to save a file in current directory .. ?!!! i mean ...

  1. #1
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493

    How to save a file in curent directory?

    hi guys ... i wonder how is it possible to save a file in current directory .. ?!!!
    i mean i wanna save files in a current directory as the exe files running
    is that clear enough or i should explain a bit more?

    tanx in advance

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Do you mean "in the current directory" as defined by "GetCurrentDirectory()" or similar would give you back? If so, just open a file for writing without specifying a directory, and it will be where you are at the moment.

    If on the other hand you require the directory from which the application was started, it's a bit harder - if this is what you want, search the forum.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    hi mat ..
    see i mean , when sb runs my program somewhere , if there is any need to save the stuff thats been calculated using my prog , it saves where the program started ,,,
    for example the program is located on the desktop .. and when you run it and now you wana save sth ,it saves on the desktop ..
    is that clear?
    by the way im a noob to Win APIs please tell me how i can Master the APIs and learn them great
    tanx in advance

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm quite sure there's an easy answer, but I don't know it. I'm quite sure someone else will come forward, but why don't you try searching the forum first - I'm sure that you can find it if you search for "save data same directory application" or some such.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Aia
    Aia is offline
    Beautiful to C Aia's Avatar
    Join Date
    Jun 2007
    Posts
    124
    Quote Originally Posted by Masterx View Post
    ... i wonder how is it possible to save a file in current directory .. ?!!!
    i mean i wanna save files in a current directory as the exe files running
    How would you save a file in another directory? I guess I am missing something in your question.
    if you code:

    fp = fopen( "filename", "w" ); That would create a filename file to write into it, in wherever place that your .exe is.
    Once you're done with it. fclose( fp );

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,022
    If another directory is active rather than the one the app lies in, you can get it using GetModuleFileName or something, I believe.
    It returns the full directory (including filename) to your EXE. Then switch to that directory and save using typical file-saving functions such as fopen/fwrite/fclose.

  7. #7
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    first of all tanx Mat .. i ll do searching before i post ...
    and
    Quote Originally Posted by Aia View Post
    How would you save a file in another directory? I guess I am missing something in your question.
    if you code:

    fp = fopen( "filename", "w" ); That would create a filename file to write into it, in wherever place that your .exe is.
    Once you're done with it. fclose( fp );
    well i know this .. i can ask the user to enter a path(sth like this scanf("%s",Path);and the fp=fopen(Path,"w"); and then save the stuff .. but i dont want any hassle...
    all i want is you find a way to save it in a directory where its running
    ( i wonder how some guys do it ...)

    and
    If another directory is active rather than the one the app lies in, you can get it using GetModuleFileName or something, I believe.
    It returns the full directory (including filename) to your EXE. Then switch to that directory and save using typical file-saving functions such as fopen/fwrite/fclose.
    Ok let me try this and tell you what happens

    tanx guys
    Last edited by Masterx; 11-17-2007 at 09:05 PM.

  8. #8
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    or to find the current directory use pwd command to get the current working directory and start saving the file in there.

    ssharish

  9. #9
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    tanx dude

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Save a file with a name in a variable?
    By guriwashere in forum C Programming
    Replies: 2
    Last Post: 06-01-2009, 05:03 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 04:53 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  4. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 02:19 PM
  5. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21