472,811 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 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 4718
<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
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.