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

Thread: User dir

  1. #1
    Join Date
    Nov 2006
    Posts
    292

    User dir

    Hi all. How would i go about making a prog that would make a dir in the home dir for linux with out knowing what the user name is? For example, if i have /home/someguy/ as a file path, how would i write that in some code?

    Code example

    Code:
    char buffer="mkdir /home/";
    system(buffer);
    Does that make sense? If not let me know so i can elaborate. Thanx in advance!

  2. #2
    Join Date
    Nov 2006
    Posts
    292

    Re: User dir

    Anyone? Isnt there a function to look up the file path of the current user? Like Windows GetDirectory() API ? .....

  3. #3
    Join Date
    Mar 2007
    Location
    Montreal, Quebec, Canada
    Posts
    185

    Re: User dir

    In unistd.h there is a function called getcwd() that gets the current working directory.

    You can use getenv (in stdlib.h) to get the HOME environment variable, which is by default /home/username/:
    Code:
    cout <<getenv("HOME") <<endl; //outputs "/home/rob" - my name is rob

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