nw i hv been tryin a stuff tht m really nt sure if u guys understnd at once..bt sum1 hs to find a solution for it plzzzzzzzzzz...

i need a code in C++ to do the following tasks...:-

1.) copy files from a folder
2.) save them in a different location as text files
3.) the files r of two types .cap n .inf. so i wnt to search each of the .cap files...
4.) make a folder of the name of the number that is inside it n then put the respective .cap flie as well as .inf file in the folder...
5.) the number inside the .cap file helps me to make a folder of tht name as previously sd n thn put the respective .cap file in it also the name of the .cap file helps to search its respective .inf file n den add tht too in the folder.

NOTE:- the name of the .cap file has lst 6 alphanumeric characters of the serial number in the rspective .inf file...n its .inf file has the same name as the serial number inside it...

does sum1 make a solution for it..???
i m wrkin on DevC++

nw i hv been tryin a stuff tht m really nt sure if u guys understnd at once..bt sum1 hs to find a solution for it plzzzzzzzzzz...

i need a code in C++ to do the following tasks...:-

1.) copy files from a folder
2.) save them in a different location as text files
3.) the files r of two types .cap n .inf. so i wnt to search each of the .cap files...
4.) make a folder of the name of the number that is inside it n then put the respective .cap flie as well as .inf file in the folder...
5.) the number inside the .cap file helps me to make a folder of tht name as previously sd n thn put the respective .cap file in it also the name of the .cap file helps to search its respective .inf file n den add tht too in the folder.

NOTE:- the name of the .cap file has lst 6 alphanumeric characters of the serial number in the rspective .inf file...n its .inf file has the same name as the serial number inside it...

does sum1 make a solution for it..???
i m wrkin on DevC++

Hello Himani,

I think you are in wrong place, here people don't solve your assignments or requirements... If you have some particular error or problem, then i assure you people will help you. Hope you will do it yourself if you try little hard.Thanks

Hello Himani,

I think you are in wrong place, here people don't solve your assignments or requirements... If you have some particular error or problem, then i assure you people will help you. Hope you will do it yourself if you try little hard.Thanks

listen dear i need hlp n tht s clear..if u cnt hlp fine...
bt mayb dere s sum1 around who cn actually pose hlp..
thnku..

does sum1 make a solution for it..???
i m wrkin on DevC++

No. We do not write your program for you, but we will help you write it yourself. Show us some effort, such as post the code you have tried, and ask specific questions about your code. But do no expect anyone here to do your homework for you, that's your job, not ours.

i very well knw tht..
n first plz if u cn stp being tht rude..

i hv been successful in making the code tht helps me do the complete task bt for a single file...
nw hw do i manage to gt all the files n do the searches..??

#include<fstream>
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	char c,c1,c2,c3,c4,c5,c6,c7;
	char PLO[16],fn1[50],fn2[50],cmd[50];
	c1=c2=c3=c4=c5=c6=c7=0;
	int flag=1;
	ifstream fin,gin;
	ofstream f1,f2;
	fin.open("2100DC.cap",ios::in);
	if(!fin)
		cout<<"Cannot open file"<<endl;
	while(fin&&flag)
	{
	c7=c6;
	c6=c5;
	c5=c4;
	c4=c3;
	c3=c2;
	c2=c1;
	fin.get(c1);
	//cout<<c6<<c5<<c4<<c3<<c2<<c1;
	if((c6=='<')&&(c6=='<')&&(c5=='O')&&(c4=='R')&&(c3=='D')&&(c2=='E')&&(c1=='R'))
		flag=0;
	}
	int count=0;
	fin.get(c);
	c='1';
	while(c!='<')
	{
	fin.get(c);
	if(c!='<')
	PLO[count++]=c;
	};
	PLO[count]='\0';
	fin.close();
	cout<<"The PLO number is "<<endl;
	for(int i=0;i<count;i++)
		cout<<PLO[i];
	cout<<endl;
	sprintf(cmd,"mkdir %s",PLO);
	system(cmd);
	sprintf(cmd,"cd %s",PLO);
	system(cmd);
	sprintf(fn1,"%s/%s.cap",PLO,PLO);
	f1.open(fn1,ios::out);
	gin.open("INA92100DC.inf",ios::in);
	sprintf(fn2,"%s/%s.inf",PLO,PLO);
	f2.open(fn2,ios::out);
	while(gin)
	{
	gin.get(c);
	f2.put(c);
	}
	fin.open("2100DC.cap",ios::in);
	while(fin)
	{
	fin.get(c);
	f1.put(c);
	}
	system("PAUSE");
}

tht s it...

It would be helpful if you posted the contents of that *.cap file. The code you have posted is a bit confusing to follow, so knowing the file contents will help us help you.

even after posting the code if none can help..well fine then..

anyways thanks...

yes certainly i understand that it may be a problem to understand it...
but i cannot post the complete file in here..
the only thing that i can do is to copy the first line of the file as it will help you know that which name folder is being made...
<YUPS><SENDER>SDV</SENDER><SN>INA92100DC</SN><ORDER>00410739270100</ORDER>

now the number after <order> is what i have to make use of...

with the code above i was able to create a folder with the name 00410739270100 as required and add the .cap file and .inf files to it but the problem as you might have observed is that first i am actually reading the files manually and secondary when the files are added to the folder the lose their name and take up the name of the folder with their extensions...

i very well knw tht..
n first plz if u cn stp being tht rude..

i hv been successful in making the code tht helps me do the complete task bt for a single file...
nw hw do i manage to gt all the files n do the searches..??

He isn't rude, he is only trying to help you, if you don't want that then you shouldn't waste your time here.

even after posting the code if none can help..well fine then..

anyways thanks...

Yes, you have posted your code, but we need to be able to do exact the same things as you do, to get a better understanding of the whole problem, if you'd for example posted the .CAP file, we can see exactly how your program is dealing with it.
BTW, Have some patience, we're not mind readers, we're not clair-voyant, instead we're just normal humans (I hope so :P), like every other human (with minor exceptions :P).

Anyway, I suggest you to read this: http://catb.org/esr/faqs/smart-questions.html

It would be much simpler to read the file an entire line at a time, then search the line for <order> tags

string line;
size_t pos;
while( getline(fin, line) )
{
    if( (pos = line.find("<order>")) != string::npos )
    {
          string name = line.substr( pos+1 );
          pos = name.find("</order>");
          name = name.substr(0, pos);
          // now you have the text between <code> and </code> tags
    }
}

It would be much simpler to read the file an entire line at a time, then search the line for <order> tags

string line;
size_t pos;
while( getline(fin, line) )
{
    if( (pos = line.find("<order>")) != string::npos )
    {
          string name = line.substr( pos+1 );
          pos = name.find("</order>");
          name = name.substr(0, pos);
          // now you have the text between <code> and </code> tags
    }
}

thankyou ..seriously didnot think of it..

He isn't rude, he is only trying to help you, if you don't want that then you shouldn't waste your time here.


Yes, you have posted your code, but we need to be able to do exact the same things as you do, to get a better understanding of the whole problem, if you'd for example posted the .CAP file, we can see exactly how your program is dealing with it.
BTW, Have some patience, we're not mind readers, we're not clair-voyant, instead we're just normal humans (I hope so :P), like every other human (with minor exceptions :P).

Anyway, I suggest you to read this: http://catb.org/esr/faqs/smart-questions.html

oh thanks for the URL....
it is really nice of you to do that stuff...

To get a list of all the *.cap and *.inf files you need to call win32 api functions FindFirstFile() and FindNextFile(). This would be very simple to do in a managed CLR program, but somewhat a mess in plain c++ programs.

vector<string> capList;
WIN32_FIND_DATA data;
HANDLE hFile = FindFirstFile("c:\mydir\*.cap", &data);
if( hFile != INVALID_HANDLE_VALUE)
{
    do {
         if( strcmp(data.cFileNam,".") != 0 && strcmp(data.cFileNam,"..") != 0 && !(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
          capList.push_back(  data.cFileNam );
   } while( FindNextFile(hFile, &data) != ERROR_NO_MORE_FILES);
}

To get a list of all the *.cap and *.inf files you need to call win32 api functions FindFirstFile() and FindNextFile(). This would be very simple to do in a managed CLR program, but somewhat a mess in plain c++ programs.

vector<string> capList;
WIN32_FIND_DATA data;
HANDLE hFile = FindFirstFile("c:\mydir\*.cap", &data);
if( hFile != INVALID_HANDLE_VALUE)
{
    do {
         if( strcmp(data.cFileNam,".") != 0 && strcmp(data.cFileNam,"..") != 0 && !(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
          capList.push_back(  data.cFileNam );
   } while( FindNextFile(hFile, &data) != ERROR_NO_MORE_FILES);
}

i am highly obliged to receive the piece of code becauz it has been a week now that i am trying out this stuff..
thankyou ...

i would like to thank evryone out there who came forward to help me..
finally i m done with my coding stuff and the program is working great...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.