I can't move from c: to D: or any other drive

X

Xohaib

Hi GUYS!
i am facing a problem in this program chechk it.

#include<iostream.h>
#include <stdlib.h>
void main()
{
system("D:");
system("dir");

}


the problem i face over here is that it can't move to d drive it shows
the files in c:
mean dir in c:


So how can i use it ?
 
G

Guest

Hi GUYS!
i am facing a problem in this program chechk it.

#include<iostream.h>
#include <stdlib.h>
void main()
{
system("D:");
system("dir");

}


the problem i face over here is that it can't move to d drive it shows
the files in c:
mean dir in c:

Kind of off-topic since it involves how the command interpreter in
Windows works, for future questions of this nature please ask in a group
discussing Windows or Windows programming.

The reason the above does not work is that each call to system starts a
new instance of the command interpreter and what you did in the first
does not affect the second. What you want to do is to run several
command in one system() call, you can do this by using && (and probably
in some other way).

system("D: && dir");
 
K

Kenneth Porter

The reason the above does not work is that each call to system starts a
new instance of the command interpreter and what you did in the first
does not affect the second. What you want to do is to run several
command in one system() call, you can do this by using && (and probably
in some other way).

system("D: && dir");

Perhaps the better question is, why use system() at all? The operations
presented are better effected by filesystem library calls. Some of these
are standardized and portable while others are very OS-dependent. Best to
collect what you want to do into a utility class that isolates OS
dependencies.

Such libraries are already readily available from various sources, such as
Boost, wxWidgets, and Qt.
 
X

Xohaib

Perhaps the better question is, why use system() at all? The operations
presented are better effected by filesystem library calls. Some of these
are standardized and portable while others are very OS-dependent. Best to
collect what you want to do into a utility class that isolates OS
dependencies.

Such libraries are already readily available from various sources, such as
Boost, wxWidgets, and Qt.

If want to delete some files from d: or other directory like D:
\Example then what should i do ???
 
V

Victor Bazarov

Xohaib said:
[..]
If want to delete some files from d: or other directory like D:
\Example then what should i do ???

If you know the names of the files you want to delete, use 'remove'
function. If you need to delete all of them, use 'system' with the
appropriate command to do it for you. If you can't find the proper
command, you need to look through the available tools (API) for the
platform you're using. Your compiler probably has some (at least
rudimentary) support for programming your OS. RTFM.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,635
Latest member
SkyePurves

Latest Threads

Top