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

  • SEARCH
  • Home
  • 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 9054509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:42:29+00:00 2026-06-16T13:42:29+00:00

I need to perform a certain file operation in C++, like this: Find and

  • 0

I need to perform a certain file operation in C++, like this:

  1. Find and delete all files in a given directory.
  2. Find if a given file exist, if yes, delete it, etc.

Please advise me a C++ solution/library which will work for both android and iOS platform.

  • 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-16T13:42:30+00:00Added an answer on June 16, 2026 at 1:42 pm

    C++ gives you provisions for file interaction.

    I will show you my FileReader class which employs a bit of C style file handling using C++.

    // BEGIN HEADER
    #include <stdio.h>
    #include <exception>
    #include <stdexcept>
    
    #define DISALLOW_COPY(type) \
        type(const type&); \
        void operator=(const type&)
    
    class FileReader { // RAII applies to file contents
        FILE *file; // c-style open/close
        DISALLOW_COPY(FileReader);
    protected:
        unsigned char *data; // local copy
        long size;
    public:
        FileReader(const char *filename);
        ~FileReader();
        unsigned long getSize();
        unsigned char *getFileData();
    };
    // END HEADER
    
    FileReader::FileReader(const char *filename) {
    
        file = NULL; data = NULL;
        if (!(file = fopen(filename, "rb"))) { throw std::runtime_error(std::string("File could not be opened: ")+filename); }
        fseek(file,0,SEEK_END);
        size = ftell(file);
        rewind(file);
        data = new unsigned char [size];
        VERIFY(size == (long)fread(data, 1, size, file)); // debug macro (just ignore it)
        fclose(file);
    #ifdef DEBUG
        PRINT("FileReader opening file "); printf("%s, %ld bytes.\n",filename,size);
    #endif
    }
    FileReader::~FileReader() {
        delete[] data;
    }
    unsigned char *FileReader::getFileData() { return data; }
    unsigned long FileReader::getSize() { return size; }
    

    I will note that you probably want to avoid using C++ to list files in the directory if you can. Why can you not simply assume whether or not certain files will be there or not be there? I’ve done a bit of game programming and pretty much the only times you need to worry about the filesystem are for logging purposes or for loading assets. For both of these you can pretty much just assume what their paths are.

    In addition, you may want to look at the remove function for deleting files. I can’t come up with any raw code in C++ for performing the task that ls is meant for. I wouldn’t use C++ to do such a task (hint: ls is a pretty neat program).

    Also take a look at stat and opendir (thanks Ben) which should be available on your platforms. Another point to make is that a task such as listing files in a dir are generally things you’re gonna want to ask your OS kernel to do for you.

    A more high-level approach mentioned by another answerer is Boost Filesystem, which is a solid choice as Boost usually is: Take a look at this directory iteration example.

    From a game programming perspective I’ve tended to lean on stuff like Lua’s os(). For example if you have a Python program you could just do something like os.system("ls") to get your dir contents assuming you have an ls program available.

    You could also exec the ls program from your C++ program.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to perform some operations on all folders within a file share which
So I have a selector that need to be perform after certain amount of
In a csh script, I need to perform something only if a certain command
I need to perform a find and replace using XSLT 1.0 which is really
We need to perform the following operation in our database : There is a
I need to determine what file type a file is and then perform a
I'd would like to make a method that would perform a certain task plus
I need to continuously read a log file to detect certain patterns. How can
I'm creating a simple application in Vb.net where I need to perform certain validations.
I need to perform a query whereby I can extract certain document entry numbers

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.