ccplusplus.com
Learn C, C++ Concepts
Thursday, January 5, 2012
chdir system call c example
/******************************************************** * File : chdir.c * Author : Saurabh Gupta * Description : chdir example c * Date : AM 011:13 05 January 2012 * Source : www.ccplusplus.com/p/c.html * Note : *******************************************************/ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> const char * const path = "/home/sgupta/Public/test"; const char * const file = "chdir-demo.txt"; int main () { printf ("Changing directory to <%s>\n", path); if (chdir (path) == -1) { printf ("chdir failed - %s\n", strerror (errno)); }else { printf ("chdir done !!!\n"); printf ("directory content of '%s'\n\n", path); system ("ls -l"); printf ("\n"); printf ("checking the content of '%s'\n", file); system ("cat chdir-demo.txt"); } return 0; } /* * OUTPUT * [sgupta@rhel6x64 Public]$ pwd /home/sgupta/Public [sgupta@rhel6x64 Public]$ gcc chdir.c -o chdir [sgupta@rhel6x64 Public]$ ./chdir Changing directory to </home/sgupta/Public/test> chdir done !!! directory content of '/home/sgupta/Public/test' total 4 -rw-rw-r--. 1 sgupta sgupta 151 Jan 5 12:54 chdir-demo.txt checking the content of 'chdir-demo.txt' -------------------------------- chdir example demo -------------------------------- I am in /home/sgupta/Public/test -------------------------------- [sgupta@rhel6x64 Public]$ */
See Also:
chdir system call
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment