-
June 25th, 2008, 02:26 PM
#1
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!
-
June 26th, 2008, 07:22 AM
#2
Re: User dir
Anyone? Isnt there a function to look up the file path of the current user? Like Windows GetDirectory() API ? .....
-
June 26th, 2008, 11:51 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|