CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Directory Path

  1. #1
    Join Date
    Jul 1999
    Posts
    90

    Directory Path

    I need to set a path based on a varible.
    a CString holds a dir name ... ex. AC1019

    so i need to set the path similar to this
    char dir[128] = "c:\\AC1019\\*.*";


    but the AC1019 has to change depending on what directory the user chose how do I do that?


    Tony



  2. #2
    Join Date
    Jun 1999
    Location
    Canada - Québec
    Posts
    273

    Re: Directory Path

    i am not sure that i understand..
    if yes.. try this :
    strcpy(dir,"C:\\");
    strcat(dir,m_string); //m_string is your CString
    strcat(dir,"\\*.*");

    if i dont understand.. give more info .. thanks..


  3. #3
    Join Date
    Jul 1999
    Posts
    90

    Re: Directory Path

    Perfect!
    Thanks so much

    You don't know anything about setting registry setting for a program do you?

    Tony


  4. #4
    Join Date
    Apr 1999
    Posts
    11

    Re: Directory Path

    Use strtok to find out the first \ and then use that pointer to copy characters from CString depeding upon its length



  5. #5
    Join Date
    May 1999
    Location
    Mass, USA.
    Posts
    103

    Re: Directory Path

    Tony,

    Since you're using CString, it's better to do:


    CString strDir;
    CString strWildcard;

    strDir = "AC1019";
    strWildcard.Format ("C:\\%s\\*.*", strDir);




    This has the advantage of being internationalized, if you choose to build your product for languages other than English.

    Another tip - as far as possible, don't use literal strings like "C:\\". Instead, create a string resource and use that to format strDir.

    For example, create a string resource (ID = IDS_Wildcard) that contains "C:\\%s\\*.*" and do the following:


    CString strDir;
    CString strWildcard;

    strDir = "AC1019";
    strWildcard.Format (IDS_Wildcard, strDir);




    This makes the code much more maintainable, since the wildcard spec is isolated in a single location.

    /ravi



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

Featured