473,789 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4942
<pe******@gmail .comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.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_it erate 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(file name.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.l earn.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
2972
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 problems with the http://www.mvps.org/access/api/api0002.htm but it only browse to folders.
5
3233
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 drive to store these images, under the assumption that no one will originally save them to that location. To resolve this, I need to copy the file to this location without possibility of user error in selecting the correct folder (the DB is to be...
1
3383
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 suggestion for improvements or conversion to iteration would be much appreciated
2
16265
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 fread() or the Visual C specific(?) read() they return that the number of bytes read equals the number of bytes requested, however all of the bytes read turn out to have a value of zero (the file contains other values). When using the exact same...
4
5985
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 the data in. However, it takes about 20 seconds to complete and I wonder if there is a faster way. For example, I found that I could use 'fread' to read the data into a string that looks like this:
2
3253
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 between plain ASCII files I receive and the Unicode ones would be to check if the first two bytes read 0xFFFE. But nothing I do seems to be able to do that. I tried reading it in binary mode and reading two characters in:
4
1487
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 thousand or so messages in the queue). I know why. It's because my code to grab a single message off the queue looks something like this :
18
34846
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."? Have you looked around trying to find simple solutions but didn't want to wade through pages of complex code? Have you balked at paying for premade solutions that are probably overkill for your particular project? I'd like to walk you through the...
0
1771
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 times it gives the error and ends the function. This function is called from an other function that scans al the files on the disc. Is it possible to give an error but that the program continues with the next file ? =============================...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
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 we have to send another system
3
2909
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.