Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

remove command with wildcard characters?

Posted on 2003-03-21
4
Medium Priority
?
195 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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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 opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

578 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