The easiest way to move files in a C program is to call link. This will create a hard link to an existing file. Once your link is there you can remove the old link. Here is a
simple sample program:
Code:
#include <unistd.h>
main( int argc, char *argv[])
{
char strOldFile[256];
char strNewFile[256];
strncpy( strOldFile, argv[1], sizeof( strOldFile ) - 1 );
sprintf( strNewFile, "trash/%s", argv[1] );
link( strOldFile, strNewFile );
unlink( strOldFile );
}
This program has about a thousand things that can fail. You must check the size of argv[1] before using sprintf. And the return code from link and unlink should be checked.
Using link may be easy, but it has it's set of problems. Hard links
CANNOT cross file systems. For this reason any program that moves files should check for the "EXDEV" return code and do a copy instead. I wrote a simple copy program long ago:
http://www.linuxquestions.org/questi...?threadid=1402
You also mentioned that you need to search for string patterns in file names. Look at the function "fnmatch". This method checks a string for a regular expressions and returns true if thre is a match. So you could search for something like "^old_*" and it would match files like:
old_fart
old_dude
But Not:
crusty_slow_old_java
Hope this helps.
Gary