Jump to content

Brute Force FileClose()


J_Y_C
 Share

Recommended Posts

I have a script that opens, copies and uses all kinds of temporary files, but I can't seem to get them to delete for the life of me. I have poured over and over anywhere I have a fileopen() or a filefindfirstfile(), and I can't find a single spot where I didn't close the handle.

To make matters more complicated, very often the file handle's name is built from a multitude of other variables. So, I guess I have 3 questions:

1. Is there a way I can just FileClose() ANY remaining open file?

2. If I cast 2 or 3 variables to another variable, and then FileOpen() or FileFindFirstFile() that variable, do I have to fileClose() just the one variable, or the lot of them?

3. Other than being poor practice, does it cause problems if I fileClose() something that I didn't need to?

Link to comment
Share on other sites

  • Developers

All FileOpen() and FileFindFirst() statements will return a FileHandle which will ALL have to be closed.

There in no problem when you try to close a FileHandle thats isn't open anymore, but I fail to understand why you would ever lose track of the open files... :P

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I have a script that opens, copies and uses all kinds of temporary files, but I can't seem to get them to delete for the life of me. I have poured over and over anywhere I have a fileopen() or a filefindfirstfile(), and I can't find a single spot where I didn't close the handle.

To make matters more complicated, very often the file handle's name is built from a multitude of other variables. So, I guess I have 3 questions:

1. Is there a way I can just FileClose() ANY remaining open file?

2. If I cast 2 or 3 variables to another variable, and then FileOpen() or FileFindFirstFile() that variable, do I have to fileClose() just the one variable, or the lot of them?

3. Other than being poor practice, does it cause problems if I fileClose() something that I didn't need to?

Bet'cha this gets it done:

Func _CloseAllFiles()
     Shutdown(6)
EndFunc

But you see the problem... The trouble to recode every FileOpen() to _FileOpenTrack() might be better spent improving you code to avoid needing this.

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks people. Psalty, I appreciate your help, and I feel bad that you spent time (not that I'm suggesting that it took you a long time) writing those functions for me, as I figured out my problem.

But perhaps I can help others by detailing what I did wrong. So, in my script I had some spots where I would fileopen() or filefindnextfile(), but I wouldn't always do it by casting it into a variable. I would just do, say,

DirCreate($IDs[$QN])
FileChangeDir($IDs[$QN])
FileOpen($IDs[$QN] & ".cue",2);opens the cuesheet
oÝ÷ Ù8^(ºWm¯+h~)^rZ,{;4ߤ
jjjº¹ê®¢Ü!È]¡ë'ßÛp¢¹+ajج!Ú'ßÛdºÒ-)ä"f²z0­Ýý²·¥j׶+y§l¢g°êÞ{az¥¥ø¥zÊ&{^­â-)䶭Êjw¢¶«ºÇnÊ%º×¯j[³­§âê)zw(f§vò¢çë~)^©ÝëºÜ¨ºÈhºWgßÛn±æè¶-)䶭¬zÊ&zØbajÙÞyÛ-¡·¦¢·Æbr+Z×^µ¨¥yا¶¡zZ_WºÒ
޲Ĩ¢w"·,ÞvØb°!jxvØ^¥ªí²ØZµØ¶§ÉbëajÛhjëh×6      
DirCreate($IDs[$QN])
FileChangeDir($IDs[$QN])
$cueSheet=FileOpen($IDs[$QN] & ".cue",2);opens the cuesheet
oÝ÷ ٩ݶ§Â¸­zÚ"·­«­¢+Ø)¥±]É¥Ñ ÀÌØíÕM¡Ð°ÅÕ½ÐìQI
,ÅÕ½ÐìµÀìÀÌØíàµÀìÅÕ½ÐìU%

and then closed it with fileclose($cueSheet).

And that totally fixed it!

Please understand, I've only been coding for about 4 or 5 months now. I'm working on my Java certification, but other than that have no education in code (though I do have an education, and work as a professional audio engineer). Since most of my textbooks are help files (though I do have a few Java books), and my instructors are strangers on forums, I find myself making a lot of stupid mistakes.

I don't typically rely on the kindness of strangers, but in this case it has worked quite well for me!

Thanks to everyone on this forum for all your interest and patience, I am most appreciative.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...