Skip navigation
Currently Being Moderated

How do I know if this variable is a file handle?

Jul 27, 2012 10:01 AM

G'day

(This has also been posted on StackOverflow)

Say I have this code:

function doFileStuff(){
   
var file = "";
   
try {
        file
= fileOpen(filePath);
       
// do stuff with file
   
}
   
finally {
        fileClose
(file);
   
}
}

If the fileOpen() process fails, the fileClose() call will error. What I need to do is this sort of thing (pseudocode):

if (isFile(file)){
    fileClose
(file);
}

I know I can test if file is an empty string still, and this works for me here, but it's not testing what I should be testing: whether file is a file handle. I can check the object's Java class, but this again sounds a bit hacky to me, and there should be a CFML way of doing it.

There should be something like just isFile(), shouldn't there? I can't find anything like this in the docs.

Any thoughts / tips? I have gone into more depth in my investigations on my blog. it's too wordy for here.

Cheers for any help.

 

--

Adam

 
Replies
  • Currently Being Moderated
    Jul 27, 2012 11:34 AM   in reply to Adam Cameron.

    Since "file = fileOpen(filePath)", can't you just remove the "file = ''" and check to see "if file" in the finally part?

     

    ^_^

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points