Bulk Rename of files In a Directory (C sourcefile)

//Code tested in Linux and SOLARIS
//Should be customized for individual use

#include "stdio.h"
#include "dirent.h"
#include "errno.h"

char *newname(char *,int,int);
int main()
{
char dirname[20]="ren";
DIR *pdir;
struct dirent *pfile;
char filename[20]="renji";
char tmppath[25];
static int i=0;
static int len;
len = strlen(filename);

//printf("Enter Directory name:");
//scanf("%s",dirname);
pdir = opendir(dirname);
if(NULL == pdir)
{
printf("Error Opening Directory\n");
exit(0);
}

//printf("Enter the staring name:");
//scanf("%s",filename);
while(pfile = readdir(pdir))
{
if(0 == (strcmp(pfile->d_name,".")))
continue;
else if(0 == (strcmp(pfile->d_name,"..")))
continue;
else
{
i++;
printf("the file names=%s\n",pfile->d_name);
strcpy(tmppath,dirname);
strcat(tmppath,"/");
strcat(tmppath,pfile->d_name);
//printf("The tmppath=%s\n",tmppath);
//printf("The filename=%s \n",newname(filename,i,len));
char newtemp[25];
strcpy(newtemp,dirname);
strcat(newtemp,"/");

if(i<10) name="%s\n" filename="%s" i ="%d\n">

0 comments: