Results 1 to 4 of 4

Thread: Retrieving current dir

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    Hello!

    How can I retrieve current dir (where my EXE is placed, like in vb App.Path)?
    And which are alternatives of Left() and Right() VB function in VC++?
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    When you start a console app (using main), argv[0] contains the full path and filename of your executable, for example c:\myprog\myprogram.exe.
    To use equivalents of Left and Right, simply use strncpy in this way:
    Code:
    char *pcSrc = "Hello World";
    char *pcDest = new char[length+1];
    strncpy(pcDest, pcSrc+offset, length);
    pcDest[length] = 0; // Terminator
    This code reproduces Left. To use Right, you'd have to count backwards from the end of the string.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    I'm developing a MFC app.
    Is argv[0] the same in MFC as in console app or do I have to do something else?
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  4. #4
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    You can use the GetCurrentDirectory function in Win32/MFC apps.
    Code:
    TCHAR tcCurDir[MAX_PATH];
    GetCurrentDirectory(MAX_PATH, tcCurDir);
    // tcCurDir now contains the current directory.
    // At least, it should be. :rolleyes:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width