Thread: getting a file's path and filename

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    getting a file's path and filename

    i'm using the an OPENFILENAME object called ofn, and in my function that opens a file, I need to find the filename and file path of the file that the user selects

    anyone know how to do this? (I searched the boards quickly and didn't find anything)

    Thanks
    -Chris

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    From the help file for GetOpenFileName()...

    >>>
    Return Values
    If the user specifies a filename and clicks the OK button, the return value is nonzero. The buffer pointed to by the lpstrFile member of the OPENFILENAME structure contains the full path and filename specified by the user.

    If the user cancels or closes the Open dialog box or an error occurs, the return value is zero. To get extended error information, call the CommDlgExtendedError function, which can return one of the following values:

    CDERR_FINDRESFAILURE CDERR_NOHINSTANCE
    CDERR_INITIALIZATION CDERR_NOHOOK
    CDERR_LOCKRESFAILURE CDERR_NOTEMPLATE
    CDERR_LOADRESFAILURE CDERR_STRUCTSIZE
    CDERR_LOADSTRFAILURE FNERR_BUFFERTOOSMALL
    CDERR_MEMALLOCFAILURE FNERR_INVALIDFILENAME
    CDERR_MEMLOCKFAILURE FNERR_SUBCLASSFAILURE
    <<<
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    From the help on
    BOOL= GetSaveFileName(&OPENFILENAME);

    Return Values
    If the user specifies a file name and clicks the OK button and the function is successful, the return value is nonzero. The buffer pointed to by the lpstrFile member of the OPENFILENAME structure contains the full path and file name specified by the user.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Don't you hate that!!

    adrianxw, you asked about Aussie rules football and Cricket pitches being the same size.
    Yes it is because offseason the same ground is used. Also there are so many members on a team of Aussie Rules, got to have room.
    In the country (outback) the inside area of horse race track, the event that brings in the punters (team members), was used.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    49
    GetOpenFileName (&ofn)

    gets the filename and stores it in

    ofn.lpstrFile

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting just the filename from a path
    By deviousdexter in forum C# Programming
    Replies: 7
    Last Post: 11-26-2008, 01:56 PM
  2. Scan filename and make a list
    By Schouf in forum C Programming
    Replies: 14
    Last Post: 11-21-2008, 06:29 PM
  3. Using string operations to save part of a file path
    By JackR in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2007, 03:48 PM
  4. user defined path for FILENAME
    By drdigimon in forum C Programming
    Replies: 5
    Last Post: 10-12-2003, 06:04 PM
  5. opening multiple files sequentially
    By moonwalker in forum C Programming
    Replies: 5
    Last Post: 08-20-2002, 09:57 PM