Goodday, I have script,that loops all files in directory, but I need to hide console while looping them this way.
Here is part of script:
#include <iostream>
#include <fstream>
#include <Windows.h>
using namespace std;
int GetFilesInDirectory(const char * dir,string dest[],unsigned int max){
string loc=dir;
int ctr=0;
if(loc.length()>2)
if(loc.substr(loc.length()-2,1)=="\\")
loc=loc.substr(0,loc.length()-1);
string opcommand;
string delcommand;
if(loc.length()>2){
opcommand="cd "+(loc)+" && dir /s /b /a > tmpfile.cpptmp";
delcommand="cd "+(loc)+" && del tmpfile.cpptmp";
} else {
opcommand="dir /s /b /a > tmpfile.cpptmp";
delcommand="del tmpfile.cpptmp";
}
system(opcommand.c_str());
ifstream f;
string line;
string fileloc;
if(loc.length()>2)
fileloc=(loc)+"\\tmpfile.cpptmp";
else fileloc="tmpfile.cpptmp";
f.open(fileloc,ios::binary);
while(f.good()){
getline(f,line);
if(line.length()>1&&ctr<max){
dest[ctr]=line;
ctr++;
}
}
f.close();
system(delcommand.c_str());
return ctr;
}
int main() {
FreeConsole();
const unsigned int filescountmax=16184;
string files[filescountmax];
int count=GetFilesInDirectory("\\",files,filescountmax);
string ext;
for(int i=0;i<count;i++){
//some script
}
}
When process starts, it hides it self, but after while it shows up cmd.exe, which closes it self.
By the way, I know there are other ways to loop files in directory, but this is easiest way to loop also files in subdirs and subdirs of subdirs and so on.
Can you help me, please?
Here is analog of system function I’ve wrote for such tasks.