N
N
Nik_Haker2015-08-04 12:07:04
Programming
Nik_Haker, 2015-08-04 12:07:04

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

3 answer(s)
S
Stanislav Fateev, 2015-08-04
@svfat

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);
}

M
maaGames, 2015-08-04
@maaGames

offtopic
Stop doing necrophilia!
VS2015 comunity is completely free + the Internet is full of documentation and studio examples.

V
Volodymyr Lavryk, 2015-08-04
@Vo0ne

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 question

Ask a Question

731 491 924 answers to any question