Answer the question
In order to leave comments, you need to log in
A very simple question in c++.?
I work in C ++ builder 6. program1
- my program, in which I need to attribute the code program2
- the program that is in the folder, and this folder is in the same place where the program is (relative address)
my program needs to do this:
if (program2 is in this folder) {
then run this program;
after that remove it from this folder
}
else{
do nothing
}
the task is to write it in c++.
Answer the question
In order to leave comments, you need to log in
Something like this, I don’t have a builder at hand, I can’t check
fname = "программа2"
if( access( fname, F_OK ) != -1 ) {
system(fname);
system("del "+fname);
}
offtopic
Stop doing necrophilia!
VS2015 comunity is completely free + the Internet is full of documentation and studio examples.
Do a search in the directory, and then organize the deletion of the file
// Для поиска файлов в каталоге и его подкаталогах напишите следующий код:
void ListFiles(AnsiString path, TStrings* List)
{
// Эта процедура выводит список файлов и вызывает
// саму себя для всех каталогов
TSearchRec sr;
if (FindFirst(path+"*.*", faAnyFile, sr) == 0)
{
do
{
if (sr.Attr & faDirectory)
{
if (sr.Name!=".")
if (sr.Name!="..")
{
ListFiles(path+sr.Name+"\\",List);// Рекурсивный вызов
}
}
else
{
AnsiString Ext=ExtractFileExt(sr.Name).UpperCase();
if (Ext==".CPP")
List->Add(path+sr.Name);
}
}
while (FindNext(sr) == 0);
FindClose(sr);
}
Application->ProcessMessages();
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ListFiles("c:\\",Memo1->Lines);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question