[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Remove a file

Posted on 2004-11-01
Medium Priority
Last Modified: 2010-04-01
I wrote a function to clear out a directory.  It will remove filenames that begin with CASE or CONFIG.   It recognizes the file, but does not remove it.  Here is the code.  I am running on a solaris machine...
const char * const CASE_FILE = "CASE";
const char * const CONFIG_FILE = "CONFIG";
bool ViewForm::cleanDirectory()

   DIR* dirp;
   dirent* dp;
   if ((dirp=opendir(msgFilePath)) == NULL)
       printf("Error polling directory\n");
       return false;

   while ((dp = readdir(dirp)))
   {    printf("file name  %s\n", dp->d_name);
        if (strstr(dp->d_name, CASE_FILE) ||
            strstr(dp->d_name, CONFIG_FILE))
   return true;
Question by:jewee
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 14

Accepted Solution

RichieHindle earned 2000 total points
ID: 12468226
You're opening msgFilePath explicitly, which implies that it's not your current working directory.  But then you're passing simple directory names rather than full pathnames to remove().  You need to either set your working directory to msgFilePath:


or build full pathnames for remove():

  char fullpath[1000];
  sprintf(fullpath, "%s/%s", msgFilePath, dp->d_name);

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question