Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Understanding I/O error 104?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: May 27, 2014 6:50 PM Last Post By: Van Swofford
Chris LeFebvre

Posts: 65
Registered: 10/24/99
Understanding I/O error 104?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2014 6:22 AM
I understand I/O 104 in general terms, the definition of it is "104 File not open for input Reported by Read, Readln, Eof, Eoln, SeekEof, or SeekEoln on a text file if the file is not open for input" but I'm getting this error in an unusual circumstance and I just can't figure out why this error is being thrown. I have a web page saved as a text file (I need to extract some information from it) and I have a number of other saved web pages as text files that I can open just fine, I use an TOpenDialog to locate and specify the file, in my code I have a a variable defined as a TextFile and in tracing through my code the error 104 is being thrown on the assign statement i.e. "Assign( I, OpenDialog1.FileName );".

I just don't understand why the Assign statement is throwing a 104 error; the file exists; the code works fine for any number of other similarly saved pages; I can open and edit the file fine in NotePad++; I've copied the text of the file inside NotePad++ and created a blank document and then pasted the text into the blank document and then "Saved As" a new different file name and I continue to get the 104 error on Assign on the new file. I've gone so far as to run a checkdsk on the volume where the file resides and run a virus scan (rebooted multiple times) and I still get this 104 error. This just seems odd to me in that the 104 error is not being reported by Read, Readln, Eof, Eoln, SeekEof, or SeekEoln but by Assign and it's not as if the file doesn't exist and I've also copied it to other locations and still get the104 error; the file attribute is just a standard 'a' (archive).

At the moment I'm using XE2 for this project.

Has anyone seen something like this and have an idea what could be causing this?

- Chris
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Understanding I/O error 104?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2014 9:39 AM   in response to: Chris LeFebvre in response to: Chris LeFebvre
Chris LeFebvre wrote:

I understand I/O 104 in general terms, the definition of it is "104
File not open for input Reported by Read, Readln, Eof, Eoln, SeekEof,
or SeekEoln on a text file if the file is not open for input" but I'm
getting this error in an unusual circumstance and I just can't
figure out why this error is being thrown. I have a web page saved as
a text file (I need to extract some information from it) and I have a
number of other saved web pages as text files that I can open just
fine, I use an TOpenDialog to l ocate and specify the file, in my
code I have a a variable defined as a TextFile and in tracing through
my code the error 104 is being thrown on the assign statement i.e.
"Assign( I, OpenDialog1.FileName );".

I just don't understand why the Assign statement is throwing a 104
error;

If you have switched I/O error checking off in the project options you
must call IOResult after each and every file operation. Otherwise a
call may error out without you noticing it, and the next one will run
into the wall since the error flag has not been cleared.

By the way: unless things have been changed on recent version
Assign/Assignfile will not raise any errors. You get them on Reset or
Rewrite if the file name is not valid. And always use full pathnames,
not plain filenames. Otherwise the outcome becomes dependent on the
application's current directory, and that can change behind your back...

Do yourself a favour and forget the old Pascal file routines (unless
you are using a really ancient Delphi version). Use TStreamReader and
TStreamWriter instead.

--
Peter Below (TeamB)
Chris LeFebvre

Posts: 65
Registered: 10/24/99
Re: Understanding I/O error 104?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2014 11:53 AM   in response to: Peter Below in response to: Peter Below
Hi Peter:

First, I/O checking is not off in project options.

In regards to "unless things have been changed on recent version Assign/Assignfile will not raise any errors. You get them on Reset or Rewrite if the file name is not valid." I'm somewhat aware of that and that's part of what's driving me crazy. This is the code
begin
  lbData.Items.Clear; 
  slNamesList.Clear;
  slMods := TStringList.Create;
  AssignFile( I, edFile.Text );
  ReSet( I );


the component edFile is a standard TEdit and the value was set from edFile.Text := TOpenDialog1.FileName and the file name is a drive letter and a completely valid path and file name; as I'm tracing through this the debugger clearly has the line "AssignFile( I, edFile.Text );" highlighted and when I hit F7 to execute that line of code that is exactly when I get the "Project GetDataFromFile.exe raised exception class EInOutError with message 'I/O error 104'." and from what I understand and what you're telling me an assignfile statement should not be throwing an I/O error of this type. So what's causing this?

Just to try something else changed the code to this:
begin
  lbData.Items.Clear; 
  slNamesList.Clear;
  slMods := TStringList.Create;
 
  slMods.LoadFromFile( edFile.Text );
 
  AssignFile( I, edFile.Text );
  ReSet( I );


So right before the assign I tried loading the file into that Tstringlist variable (which is really meant for something else later on) and that operation completed successfully and looking at the count and contents of that in the debugger it loaded the file just fine.

This code has been working fine with only minor changes since at least D2 and I'm working on this project in XE2 and I just recently got the upgrade to XE6 but I haven't migrated this project to it yet so I don't think XE2 is 'ancient'. But like I said in my original message, this code and program works exactly as it's supposed to with dozens of other similar files and no matter what I try i.e. open the file in NotePad++ / copy contents to the clipboard / create a new document / paste contents / save file as and then try with the new saved version of this file I get the exact same error in the exact same place and this file in completely read and writable with any other number of applications.

I found an example of TStreamReader and TStreamWriter and I'll migrate this program to use that and get back to you as to the results.

- Chris
Van Swofford

Posts: 397
Registered: 6/28/03
Re: Understanding I/O error 104?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2014 12:16 PM   in response to: Chris LeFebvre in response to: Chris LeFebvre
Hi Chris,

Are there any alternate data streams attached to this file? I've had
problems in the past with files that were downloaded from the internet,
where Windows attached a stream that marked the file as having come
from "the dangerous internet", and my program was unable to open it.
Just a thought for why this file might be treated differently than
others.

--
Cheers,
Van

"Good judgment comes from experience, and a lot of that comes from bad
judgment." - Will Rogers
Chris LeFebvre

Posts: 65
Registered: 10/24/99
Re: Understanding I/O error 104?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2014 6:21 PM   in response to: Van Swofford in response to: Van Swofford
Hi Van:

Thanks for the input, I really don't think I've ever read anything about "alternate data streams" just for my own knowledge how would you determine if "there were any alternate data streams attached to the file"?

Also as I outlined above one of the steps I took was to open the problem file in Notepad++ and use Ctrl-A / Ctrl-C to copy the contents to the clipboard; then create a new file and paste the clipboard into the blank file and then save the file under a new name but the new file had the same problem as the original. Can Windows really keep track of data passing between files in that manner and attach the same alternate data stream to the new file as was attached to the old, if that was the case?

- Chris
Van Swofford

Posts: 397
Registered: 6/28/03
Re: Understanding I/O error 104?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2014 6:50 PM   in response to: Chris LeFebvre in response to: Chris LeFebvre
Chris LeFebvre wrote:

Hi Van:

Thanks for the input, I really don't think I've ever read anything
about "alternate data streams" just for my own knowledge how would
you determine if "there were any alternate data streams attached to
the file"?

Also as I outlined above one of the steps I took was to open the
problem file in Notepad++ and use Ctrl-A / Ctrl-C to copy the
contents to the clipboard; then create a new file and paste the
clipboard into the blank file and then save the file under a new name
but the new file had the same problem as the original. Can Windows
really keep track of data passing between files in that manner and
attach the same alternate data stream to the new file as was attached
to the old, if that was the case?

- Chris

I don't think Windows can track the contents of a file if you copy to a
new file via the clipboard, but it will copy the streams if you just
copy the file to a new name, or move it. It also can't copy the
streams if you copy the file to a drive that is formatted with FAT32.
So you can delete any ADS by moving a file to a USB drive and back
again, for example.

Here's a good article explaining a good bit about alternate data
streams:
http://blogs.technet.com/b/askcore/archive/2013/03/24/alternate-data-streams-in-ntfs.aspx

If you google "alternate data streams" you'll find a bunch of articles
that give more information about them.

Here's a utility that can determine if there are any streams attached
to files: http://technet.microsoft.com/en-us/sysinternals/bb897440.aspx

--
Cheers,
Van

"Good judgment comes from experience, and a lot of that comes from bad
judgment." - Will Rogers
Chris LeFebvre

Posts: 65
Registered: 10/24/99
Re: Understanding I/O error 104?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2014 6:29 PM   in response to: Peter Below in response to: Peter Below
Hi Peter:

I rewrote the procedure where the problem was happening to use TStreamReader and after that I was able to read the file without any errors. So I'll make it a point to start using TStreamReader and migrating any old programs that still use the old routines over.

Thanks,

- Chris
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02