lundi 3 octobre 2016

Check files with same file name in directory?

Im a Newbie in C++.

I'm currently doing a C++ programme that Checks for file duplicates in a directory.

For example I have a directory with files: (test.dat,test1.dat,irrr.dat)

Here test.dat and test1.dat will be similar. Thus I have 2 duplicates.

Is there a way to check for similar file names as in the above example? Thanks.

Here's my current progress.

#include<fstream.h>
void main ()
{
char filename[50];
int choice;
int flag=0;
a:
cout<<"Hello there, Welcome to SGJ File Sorter"<<endl<<"     "<<"What would you like to do?"<<endl;
cout<<"1.Remove duplicate files"<<endl;
cout<<"2.Rename duplicate files"<<endl;
cin>>choice;
switch(choice){
case 1 :   {
cout<<"Input filename with extension"<<endl;
cin>>filename;
cout<<"let us see if the file exists..."<<endl;
ifstream iff(filename);
if (iff)
{
flag=1;
}
else
{
flag=0;
}
if(flag==1)
{
cout<<"it does exist"<<endl;
}
else
{
cout<<"invalid file, it does not exist"<<endl;
goto a;
}
cout<<"finding No. of files with similar file names...";

Aucun commentaire:

Enregistrer un commentaire