473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Reading files: when filename is very long

Dear comp.lang.c++,
I'm trying to read a file with very long filename using ifstream.
Although, the file exists the file open for read fails. Is there a
restriction on the size? I'm using winXP with VS2005. Please advice.
Thank you.

Oct 20 '06 #1
7 4888
<pe******@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Dear comp.lang.c++,
I'm trying to read a file with very long filename using ifstream.
Although, the file exists the file open for read fails. Is there a
restriction on the size? I'm using winXP with VS2005. Please advice.
Thank you.
Any restriction would be on the OS level. Ask in a newsgroup appropriate to
your OS.
Oct 20 '06 #2
On 20 Oct 2006 15:12:32 -0700 in comp.lang.c++, pe******@gmail.com
wrote,
>Dear comp.lang.c++,
I'm trying to read a file with very long filename using ifstream.
Although, the file exists the file open for read fails.
Where is the code? What is the error message from perror()?

This issue is covered in Marshall Cline's C++ FAQ. See the topic
"[5.8] How do I post a question about code that doesn't work
correctly?" It is always good to check the FAQ before posting.
You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/
Oct 20 '06 #3
pe******@gmail.com wrote:
Dear comp.lang.c++,
I'm trying to read a file with very long filename using ifstream.
Although, the file exists the file open for read fails. Is there a
restriction on the size? I'm using winXP with VS2005. Please advice.
Thank you.
The issue has nothing to do with a std::ifstream. Why don't you
implement a solution with error checking, or exceptions, that displays
the target filename used and perhaps a path+filename size check? Have
you considered that perhaps the issue is with spaces in the filename?

How will you know what the issue is if you don't implement some form of
error-checking?
I'll gladly supply you with an example of a simple error checking
mechanism but with no code you only get the skeleton.
I did it like this:

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <stdexcept>

class FileException : public std::exception
{
// members
public:
// parametized FileException ctor and d~tor throw()
char const* what() const throw()
{
// return relevent error data
}
};

class FileReader
{
// declare members like a std::string to hold filename
// declare a std::vector<std::stringas a dynamic container for
storage
public:
// parametized ctor with path+filename length check, XP <= 240 chars
/* member functions */
void filecheck(std::string& r_s) const
{
// throw FileException if path+filename 240 chars
}
void read()
{
// decare a std:ifstream, check for error, throw if e
// open input file stream, check for error, throw if e
// while std::getline using a buffer and load the std:vector
// check if ifs failure was *not* eof(), throw e if so
}
/* friends */
friend
std::ostream&
operator<<(std::ostream& os, const FileReader& r_fr)
{
// use std::copy to std::ostream_iterate the vector into the os
stream
// return os
}
};

int main()
{
try
{
// declare a new FileReader object with target filename + check
filename size
// call the object's read() member function
// std::cout << object; with overloaded op<<
}
catch (const std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}

/* contents of file:
string 0
string 1
string 2
string 3
string 4
*/

Do not use new / delete or the exception mechanism becomes needlessly
complicated.

Oct 21 '06 #4
pe******@gmail.com wrote:
Dear comp.lang.c++,
I'm trying to read a file with very long filename using ifstream.
Although, the file exists the file open for read fails. Is there a
restriction on the size? I'm using winXP with VS2005. Please advice.
Thank you.
Use std::string to contain the filename.
Use std::string::c_str() to get data to pass to open:
std::string filename;
//...
std::ifstream input_file(filename.c_str());
//...

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
Oct 21 '06 #5
On 20 Oct 2006 15:12:32 -0700, pe******@gmail.com wrote:
>I'm trying to read a file with very long filename using ifstream.
Although, the file exists the file open for read fails. Is there a
restriction on the size? I'm using winXP with VS2005. Please advice.
Maybe it's a problem with UNC path names or with blanks in your path?
In the latter case try additional double quotes ("") around your path.

Best wishes,
Roland Pibinger
Oct 21 '06 #6
David Harmon wrote:
On 20 Oct 2006 15:12:32 -0700 in comp.lang.c++, pe******@gmail.com
wrote,
>>Dear comp.lang.c++,
I'm trying to read a file with very long filename using ifstream.
Although, the file exists the file open for read fails.

Where is the code? What is the error message from perror()?
AFAIK, perror doesn't necessarily report errors from ifstreams.

Oct 21 '06 #7

pe******@gmail.com wrote:
Dear comp.lang.c++,
I'm trying to read a file with very long filename using ifstream.
Although, the file exists the file open for read fails. Is there a
restriction on the size? I'm using winXP with VS2005. Please advice.
Thank you.
Without seeing either the code or the filename it is hard to tell, but
if you have diagnosed the problem correctly then you will need to ask
on a Windows group.

There is an oddity on the Windows platform as the API doesn't exactly
match the capabilities of the underlying disk system NTFS. For example
NTFS is case sensitive, but the API isn't.

There's another one to do with very long file name handling, but I
don't remember the details. You'll have to ask on a Windows group to
get an answer for the right format to use for the filename.
K

Oct 22 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
5
by: IdeaMan | last post by:
Windows 2000 Access 97 I am working on an issue tracking DB, where I need to link (not attach due to size)screen prints of various system errors. I have created a public folder on a network...
1
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
2
by: JS | last post by:
Hello all! I have come on to a problem for which I am not able to find a solution searching the web. What I am trying to do is reading a log-file with a size of 1.3 GB. When reading it using...
4
by: Matthew Crema | last post by:
Hello, Say I have 1000 text files and each is a list of 32768 integers. I have written a C program to read this data into a large matrix. I am using fopen in combination with fscanf to read...
2
by: nnimod | last post by:
Hi. I'm having trouble reading some unicode files. Basically, I have to parse certain files. Some of those files are being input in Japanese, Chinese etc. The easiest way, I figured, to distinguish...
4
by: Craig Vermeer | last post by:
Hi All, I have a program that's using the file system as a queuing mechanism, and it's consuming an inordinate amount of CPU time when the file system queue gets all that large (any more than a...
18
jhardman
by: jhardman | last post by:
Have you ever wanted to upload files through a form and thought, "I'd really like to use ASP, it surely has that capability, but the tutorial I used to learn ASP didn't mention how to do this."? ...
0
Guido Geurs
by: Guido Geurs | last post by:
I'm writing a program that list the contents of a CDrom and also the contents of the ZIP files. When there is a bad Zip file on the CD, the program keeps traying to reed the file and after +- 50...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...

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.