?
Solved

remove command with wildcard characters?

Posted on 2003-03-21
9
Medium Priority
?
168 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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 5

Expert Comment

by:Kocil
ID: 8183881
void RemoveWildCard(char *path)
{
  int found;
  struct ffblk ff;
  int found = FindFirst(path, rta Downloads\\*.*", faAnyFile, &ff);

  while (ff == 0) {
    remove(ff.ff_name);
    ff = FindNext(ff);
  }
  FindClose(ff);
}

Note:
This is for Borland,
Findfirst/findnext is not portable. Checkout your compiler manual.
0
 
LVL 5

Expert Comment

by:Kocil
ID: 8183897
I forgot some &s

void RemoveWildCard(char *path)
{
 int found;
 struct ffblk ff;
 int found = findFirst(path, rta Downloads\\*.*", faAnyFile, &ff);

 while (found == 0) {
   remove(ff.ff_name);
   ff = findnext(&ff);
 }
 findclose(&ff);
}
0
 
LVL 5

Expert Comment

by:Kocil
ID: 8183945
Awww ... another mistake :) sorry.
This time I have compiled it at Turbo C++ 3.1

#include <dos.h>
#include <dir.h>
#include <stdio.h>


void RemoveWildCard(char *path)
{
  int found;
  struct ffblk ff;
  found = findfirst(path, &ff, FA_ARCH);
  while (found == 0) {
    remove(ff.ff_name);
    found = findnext(&ff);
  }
  /* findclose(&ff); */
}
0
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.

 
LVL 6

Expert Comment

by:gj62
ID: 8184051
Sorry Kocil - didn't see your respones until I posted - duh...  I think that is a Borland-specific function...

For a VisualStudio answer, see the other post

http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20559128.html

0
 
LVL 3

Expert Comment

by:wide_awake
ID: 8187210
You can also use the system() function to execute an actual command.

if you're using a UNIX-like system, you can do something like

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

here's the man page:
http://linux.ctyme.com/man/man2671.htm
0
 
LVL 3

Expert Comment

by:wide_awake
ID: 8187217
offtopic: What are we supposed to do in the case of reposts?
0
 
LVL 5

Expert Comment

by:Kocil
ID: 8188177
Ask the moderator to delete one of them.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8225215
PAQ'd and 50 points refunded

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Technology Partners: 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses
Course of the Month12 days, 6 hours left to enroll

752 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