こんにちは、ディレクトリ内のすべてのファイルをループするスクリプトがありますが、このようにループしている間はコンソールを非表示にする必要があります。スクリプトの一部を次に示します。
#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
}
}
プロセスが開始されると、プロセスは非表示になりますが、しばらくするとcmd.exeが表示され、プロセスが閉じます。ちなみに、ディレクトリ内のファイルをループする方法は他にもあることは知っていますが、これはサブディレクトリ内のファイルやサブディレクトリのサブディレクトリなどもループする最も簡単な方法です。助けてくれませんか?