Mail Archives: djgpp-workers/2000/12/31/10:39:03
> I've tried running "mv a b" with success. Doesn't mv use rename()?
No; IIRC, it is basically a cp followed by an rm, code-wise.
Then again, it's been a while since I fiddled with fileutils, so I
may be wrong.
Below is a simple program that lowercases all file and directory
names in the current dir. Does this work on WinME too?
Make sure you try it in a variety of places (network drives, dirs
with LFN files, SUBSTed drives, ...).
== start of simple proglet
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <ctype.h>
int __opendir_flags = __OPENDIR_PRESERVE_CASE;
void
decapitate(const char* name)
{
static char lowername[512];
/* Don't change a CVS directory */
if (strcasecmp (name, "CVS") == 0)
return;
strcpy (lowername, name);
strlwr (lowername);
if (strcmp (name, lowername) != 0) {
printf ("%s -> %s\n", name, lowername);
if (rename (name, lowername) != 0) {
perror (name);
}
}
}
int
main(void)
{
DIR* dp = NULL;
struct dirent* ep = NULL;
dp = opendir ("./");
if (dp != NULL) {
while ((ep = readdir (dp)) != NULL)
decapitate (ep->d_name);
(void) closedir (dp);
}
else puts ("Couldn't open the directory.");
return 0;
}
- Raw text -