?
Solved

remove command with wildcard characters?

Posted on 2003-03-21
4
Medium Priority
?
191 Views
Last Modified: 2010-04-15
I'm using the following code to remove some files before I write out the new files.

But, I'd like to simply remove all of the .csv files in the directory instead of checking each one individually.

     rc=remove(filename);
     if (rc != 0) {
          exit(rc);
     }

Is there a way to do something like this:  remove("/tmp/*.csv")
And if so, what is the syntax?

Thanks in Advance
John
0
Comment
Question by:jtrapat1
[X]
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
  • 2
4 Comments
 
LVL 6

Expert Comment

by:gj62
ID: 8184021
What platform?  On Windows, you can do:

struct _finddata_t c_file;
long hFile;

/* Find first .c file in current directory */
if( (hFile = _findfirst( "*.c", &c_file )) == -1L )
   printf( "No *.c files in current directory!\n" );
else
{
  remove(c_file.name);
  while( _findnext( hFile, &c_file ) == 0 )
  {
    remove(c_file.name);
  }

  _findclose( hFile );
}
0
 
LVL 2

Expert Comment

by:honey_hamster
ID: 8184131
You can try using the system() call, e.g.
  system( "del /tmp/*.csv" );
0
 

Author Comment

by:jtrapat1
ID: 8184353
I'm using a c program on a unix platform.
I have been using the remove command with single files but I was wondering about multiple files.

thanks
john
0
 
LVL 2

Accepted Solution

by:
honey_hamster earned 200 total points
ID: 8188562
For UNIX, using the system() function call, the code would look like:

system( "rm /tmp/*.csv" );

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

762 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