Hi...
i have this code to check if file exist already and its work,
but what i need is : is to add feature to function to see if the file already exist open same file and rename it with another name ,probably file2
assume file name is "abc.c"
this scenario like this
User>>(provide file name)
Code>>(check if file already exist show msg:
"File already (abc.c) exist would you like to create another file and rename it ("abc2.c") "maybe it need loop to search directory "????
User>>if press yes ok it will make another file with another name
but if no exit the function and dont create another file
Code:
// function to check file existence and here what i need to add the feature above
int fExist(const char* fn){
struct stat buffer;
int exist = stat(fn,&buffer);
if(exist == 0)
return 1;
else // -1
return 0;
}
and here is in the main():
Code:
int exist = fExist(filename);
if(exist)
{
printf("File already (%s) exist.\n",filename);
continue;
}
else
{
fd=open(filename,O_WRONLY |O_CREAT,mode);
printf("FIle is being downloaded ...\n");
/* write the data from file to buffer */
write(fd,buffer,sizeof(char)*strlen(buffer));
printf("Finish downloading....\n");
printf(".....................................................\n");
}