473,503 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

include (Text) files from directory (1 by 1) automatically and print what in it.

4 New Member
#include<iostream>
#include<conio.h>
#include<fstream>
#include<windows.h>
using namespace std;
int main()
{
string ptr,a;
string b="E:\\project\\";

WIN32_FIND_DATA file;
HANDLE obj = FindFirstFile("E:\\project\\*",&file);
if(obj)
{
// do
// {

ptr=file.cFileName;
a=b+ptr;
ifstream fin;
fin.open("a.txt");
char ch;

while(!fin.eof())
{
fin.get(ch);
cout<<ch;

}
fin.close();
cout<<ptr<<endl;

}
while(FindNextFile(obj,&file));

cout<<endl;

getch();
return 0;
}
Jun 10 '14 #1
4 1258
Irtaza Ijaz
4 New Member
it shows nothing.. what i have to do to read files from the directory and shows what is written in it..

Thanks in advance.
Jun 10 '14 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
Expand|Select|Wrap|Line Numbers
  1. ifstream fin;
  2.  fin.open("a.txt");
  3.  char ch;
  4.  
  5.  while(!fin.eof())
  6.  {
  7.  fin.get(ch);
  8. etc...
You are intending to open a.txt as an input file?

"a.txt" is a literal. The a in the literal is not your string a.

You might try:

Expand|Select|Wrap|Line Numbers
  1. fin.open(a.c_str());
  2.  
Jun 10 '14 #3
Irtaza Ijaz
4 New Member
i want to give just name of directory and the program will open the text file automatically?? how it is possible
Jun 13 '14 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
You have to have a complete path to the file to open it.

If you supply only the directory to the file, then your program must iterate the directory and create a path consisting of the supplied path to the directory + the name of the file then open the file using this complete path.
Jun 13 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2155
by: Walter Huf | last post by:
Okay, I'm writing a cgi program, and I can send files and stuff, but how do I send text files with word wrap enabled? If a line of text is wider than the browser, and unsightly scrollbar appears on...
4
4112
by: hoke | last post by:
I want to display plain text files in the browser. The files contain html and javascript and have a .txt extension. This works fine with files with just html. Unfortunately when showing files with...
0
2024
by: Webmaster | last post by:
Hi everyone... I know this isn't strictly a php/mysql ng, but I was hoping maybe someone here knows both languages and is willing to help. I have a directory of text files that i'd like to...
2
4302
by: Debbie CD UK | last post by:
I have a large amount of log files from an electronic contro tester that I need to import in to an Access database Unfortunately, they are not comma delimited or fixed with but different fields...
5
23034
by: gwarning! | last post by:
Goal: Have multiple text files, each of various lengths, be concatenated together into one final consolidated text file. Problem: Since the names of the files to be concatenated can change from...
14
2599
by: Dixie | last post by:
I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using...
14
2019
by: rafal_ | last post by:
Is difference between interpretation of \n only difference ?
1
2195
by: jo3c | last post by:
hi everybody im a newbie in python, i have a question how do u parse a bunch of text files in a directory? directory: /dir files: H20080101.txt ,...
1
2930
by: Trevor17 | last post by:
Hello All, I am currently in a Perl programming class and our assignment was: Create a filehandle with the open function that uses a pipe to list all the files in your current directory and...
6
21772
by: tig2810 | last post by:
Hi all This sounds easy and I'm sure it is but i'm just having so much trouble. I have a directory with text files. I want to search the text files for a string and return the name of the file that...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.