Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8606229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:02:26+00:00 2026-06-12T03:02:26+00:00

Goodday, I have script,that loops all files in directory, but I need to hide

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:02:27+00:00Added an answer on June 12, 2026 at 3:02 am

    Here is analog of system function I’ve wrote for such tasks.

    int system_hidden(const char *cmdArgs)
    {
        PROCESS_INFORMATION pinfo;
        STARTUPINFO sinfo;
    
        /*
         * Allocate and hide console window
         */
        AllocConsole ();
        ShowWindow (GetConsoleWindow(), 0);
    
        memset (&sinfo, 0, sizeof (sinfo));
        sinfo.cb = sizeof (sinfo);
        CreateProcess (NULL, (char*)cmdArgs,
                       NULL, NULL, false,
                       0,
                       NULL, NULL, &sinfo, &pinfo);
        DWORD ret;
        while (1)
        {
            HANDLE array[1];
            array[0] = pinfo.hProcess;
            ret = MsgWaitForMultipleObjects (1, array, false, INFINITE,
                                             QS_ALLPOSTMESSAGE);
            if ((ret == WAIT_FAILED) || (ret == WAIT_OBJECT_0))
                break;
            /*
             * Don't block message loop
             */
            MSG msg;
            while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE))
            {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            }
        }
    
        DWORD pret;
        GetExitCodeProcess (pinfo.hProcess, &pret);
    //    FreeConsole ();
        return pret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goodday, I have this script beneath to recognize the first tag ([Test1]) But all
Good day to all. I have a movie that need 2 be displayed with
Good day all; I have an UIImageView that I animate around a large UIView.
Good day everyone. I have an audio class, that plays a .wav file. But
Good day all, I have a preset situation that can't be changed, that revolves
Good day, I have searched far and wide but all I can find is
So I have this script that extracts a given string within a bigger string:
Good day, I have a ASP.net MVC app that needs to upload files to
Good day, I have a script in PHP that gets contents from a URL.
Good day to all. I have a booking site. Here I need to integrate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.