User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,485 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,793 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 3235 | Replies: 4
Reply
Join Date: Aug 2003
Posts: 3
Reputation: kyle is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kyle kyle is offline Offline
Newbie Poster

i = system ("cd c:\text"); :(

  #1  
Aug 23rd, 2003
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main ()
{
  int i,j;
  puts ("Trying to execute command CD ");
  i = system ("cd c:\text"); 
  if (i==-1) puts ("Error executing CD");
  else puts ("Command successfully executed");

 puts ("Trying to execute command del ");
  j = system ("del *.txt"); 
  if (j==-1) puts ("Error executing del");
  else puts ("Command successfully executed");

 getchar();
  return 0;
}


It won't work. How do I make this go to a specific directory? I know if i just make it i = system ("cd"); that it will print the current directory. Is there a way to change directories this way?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2003
Location: Austin, TX
Posts: 117
Reputation: subtronic is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 1
subtronic's Avatar
subtronic subtronic is offline Offline
Junior Poster
  #2  
Aug 23rd, 2003
system actually starts a new process, does what you want, then closes that process. in fact, if you really think about it, what does it mean to "change directory"; "change directory" or cd is a Shell implemented feature on the *system* level. With this in mind, you're best bet is to use the standard unix library.

#include <unistd.h>

and the function chdir(char *path)

man chdir
man getcwd


system is the worst function of all time, never use it.
Last edited by subtronic : Aug 23rd, 2003 at 2:56 am.
Reply With Quote  
Join Date: Aug 2003
Posts: 3
Reputation: kyle is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kyle kyle is offline Offline
Newbie Poster

Re: i = system ("cd c:\text"); :(

  #3  
Aug 24th, 2003
Where can I get unistd.h?
Reply With Quote  
Join Date: Aug 2003
Location: Austin, TX
Posts: 117
Reputation: subtronic is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 1
subtronic's Avatar
subtronic subtronic is offline Offline
Junior Poster

Re: Re: i = system (

  #4  
Aug 24th, 2003
Originally Posted by kyle
Where can I get unistd.h?

I'm sorry, at a closer look you are using Windows...I thought you were actually using C on a Unix System. I'm not sure how you'd do it with the Win32 API, I'd imagine it is quite similar.
Last edited by subtronic : Aug 24th, 2003 at 11:45 pm.
Reply With Quote  
Join Date: Aug 2003
Posts: 3
Reputation: kyle is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kyle kyle is offline Offline
Newbie Poster

Re: Re: i = system (

  #5  
Aug 25th, 2003
Originally Posted by waterdog
Shouldn’t system(“cd c:\text”);
be system(“cd c:\\text”);

Yes.

chdir("c:\\text");


By the way subtronic, on windows the chdir() function is in dir.h. Thanks alot for all the help guys
Last edited by kyle : Aug 25th, 2003 at 11:49 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 3:02 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC