just a minor correction when changing a character from uppercase to lowercase below...
1. add "#include <ctype.h>" without the qoutes with the list of #includes 2. replace "*n = *o | 0x20;" with "*n = tolower(*o);" without the qoutes 3. recompile using gcc with the same parameters OR'ing the character with 0x20 or turning on the 6th bit is a technique i used in assembly language to convert from uppercase to lowercase as long as the character to convert is in the range of A-Z and a-z which i forgot to bound check... i forgot also that there are functions toupper() and tolower() in ctype library.. sorry about that.. fooler. On Sat, Feb 21, 2009 at 1:21 AM, fooler mail <[email protected]> wrote: > On Fri, Feb 20, 2009 at 4:11 PM, Daniel Escasa <[email protected]> wrote: >> Sabi ni Fooler noong Fri, Feb 20, 2009 at 3:11 PM: >>> as like i said... if you cant find in google.. you can find it here in plug >>> :-> >> >> To clarify, Google did give me links to utilities, but they were for >> Windows. Wasn't about to boot into Windows just to run those utils. > > ok to make you happy... ill make a utility for you :-> > > a simple C program using recursive algorithm to traverse a tree or > directory and then change to lowercase.. you can compile this either > in linux or xBSD... > > #include <stdio.h> > #include <stdlib.h> > #include <sys/types.h> > #include <dirent.h> > #include <string.h> > > #define NAMELEN 256 > > void Rename(char *path, char *oldname) { > char *o, *n; > char newname[NAMELEN]; > char new[NAMELEN], old[NAMELEN]; > > for (o = oldname, n = newname; *o; o++, n++) { > *n = *o | 0x20; > } > *n = 0; > if (strcmp(oldname, newname)) { > snprintf(old, NAMELEN, "%s/%s", path, oldname); > snprintf(new, NAMELEN, "%s/%s", path, newname); > if (rename(old, new) == -1) { > perror(old); > exit(1); > } > } > } > > void RecurseDIR(char *path) { > DIR *dir; > struct dirent *drt; > char newpath[NAMELEN]; > > if ((dir = opendir(path))) { > while ((drt = readdir(dir))) { > if ((drt->d_type & DT_DIR) && !strstr("..", > drt->d_name)) { > snprintf(newpath, NAMELEN, "%s/%s", > path, drt->d_name); > RecurseDIR(newpath); > Rename(path, drt->d_name); > } > if (drt->d_type & DT_REG) { > Rename(path, drt->d_name); > } > } > closedir(dir); > } > } > > int main(int argc, char *argv[]) { > > RecurseDIR(argc == 2 ? argv[1] : "."); > > return (0); > } > > saving to let say danny.c and to compile... > > gcc -ansi -pedantic -Wall -O3 -D_BSD_SOURCE -o danny danny.c > > syntax of the program... > > danny [path] > > if there is a path.. all the files and directories under that path are > rename to lowercase.. if there is no path.. current directory is > used.. > > fooler. > _________________________________________________ Philippine Linux Users' Group (PLUG) Mailing List http://lists.linux.org.ph/mailman/listinfo/plug Searchable Archives: http://archives.free.net.ph

