sharmon
asked on
Delete a temporary file created in VB from the same program.
OK, here's my problem... I am creating some temp files from my program. After I convert them over to a format I want, I would like to delete them, but no matter what I do, file scripting object, kill, shell to dos and deltree, the files are undeletable until I exit my program. I have tried everything I can think of but am probably missing something simple or it can't be done??? I need to delete the files from my program shortly after they are created. I have tried unloading the form even and deleting them from a Shutdown routine and still no go...I cannot even delete them from Filemanager until the program ends. Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can make a separate program to delete them which pauses for a second or two then call it from you main app
shell "deleteprog"
unload ..etc
shell "deleteprog"
unload ..etc
ASKER
I will try your ideas and get back to you tomorrow thanks...
Shannon
Shannon
You need to close the files. You can't delete the files, or in some cases open the files with another application until your program closes them.
yes, I already said that.
ASKER
Ok, sorry it took me a couple days, I had to finish up some work on another program. Caraf_G, let me point this out and maybe you might have a different answer before I reject this one...ok. I know that if I open a file and write to it myself that I have to close it before I delete it...that's pretty basic. But I am not directly creating the file. I am using a third party ocx to create the file. And no matter what I do, I cannot delete the file until I have exited my program. So is there a way around that at all. A "shelled program" will not delete it as I cannot even do it manually. Is there a way to force the os to close the file regardless of my app? If it's harder I'll increase the points...if it can't be done, I'll just give them to Caraf....thanks alot for any recommendations....
Aha, in that case it seems to me that your 3rd party OCX is not closing the file.
There is only one solution to this, and it's rather naff.
Create a tiny .exe containing the 3rd party ocx control. Shell it synchronously (plenty of threads in this forum explaining how that works). When the .exe finishes, the file automatically gets closed, thereby fixing the problem caused by the OCX that does NOT close the file.
Any data that needs to be passed to the OCX can be passed via command line arguments. Again, there are quite a few threads in this forum explaining how to do that in case you don't know.
Use oldlook.experts-exchange.c om for a more useful search engine.
Good luck!
Pino
There is only one solution to this, and it's rather naff.
Create a tiny .exe containing the 3rd party ocx control. Shell it synchronously (plenty of threads in this forum explaining how that works). When the .exe finishes, the file automatically gets closed, thereby fixing the problem caused by the OCX that does NOT close the file.
Any data that needs to be passed to the OCX can be passed via command line arguments. Again, there are quite a few threads in this forum explaining how to do that in case you don't know.
Use oldlook.experts-exchange.c
Good luck!
Pino
ASKER
Thanks Caraf, I know that will work, I just didn't think about it....thanks again, take care.
In other words, somewhere in your program you open the file but you forget to close it after you're done with it.