|
-
Feb 17th, 2005, 09:01 AM
#1
Thread Starter
Frenzied Member
How to delete file in use
Hi everyone..
How to delete a file which is in use? actually i want to move a file which is in use by another process... is that possible? any ideas are welcome.. including API solution..
-
Feb 17th, 2005, 09:17 AM
#2
Re: How to delete file in use
What kind of file is it and how is it in use by the other process?
-
Feb 17th, 2005, 09:24 AM
#3
Re: How to delete file in use
 Originally Posted by moinkhan
Hi everyone..
How to delete a file which is in use? actually i want to move a file which is in use by another process... is that possible? any ideas are welcome.. including API solution..
If it is in use by Windows, windows is not going to allow you to delete it.
However, never one to be daunted by the whims or wishes of Windows, whenever I've had a need to delete a file in use by Windows, I go to DOS, navigate to the folder, and use DOS to delete. That has never failed me.
Having said that, I've never tried to 'move' a file in use, but I'd hazard a guess that you could use DOS to copy it to somewhere, then use DOS to delete it from its original location.
-
Feb 17th, 2005, 09:27 AM
#4
Re: How to delete file in use
 Originally Posted by Hack
If it is in use by Windows, windows is not going to allow you to delete it.
However, never one to be daunted by the whims or wishes of Windows, whenever I've had a need to delete a file in use by Windows, I go to DOS, navigate to the folder, and use DOS to delete. That has never failed me.
Having said that, I've never tried to 'move' a file in use, but I'd hazard a guess that you could use DOS to copy it to somewhere, then use DOS to delete it from its original location.
When one of my users is running an .EXE of mine, I cannot delete it - even from DOS. I think we've had some luck making the folder share options read only - but that was quite a while ago.
That's why I asked what kind of file and open in what way...
-
Feb 17th, 2005, 09:32 AM
#5
Re: How to delete file in use
 Originally Posted by szlamany
When one of my users is running an .EXE of mine, I cannot delete it - even from DOS. I think we've had some luck making the folder share options read only - but that was quite a while ago.
That's why I asked what kind of file and open in what way...
This is an excellent point!! If there are folder level permissions in place, then regardless of what you try, you probably won't be able to delete it, and you might not even be able to copy/move it.
-
Feb 17th, 2005, 11:27 PM
#6
Thread Starter
Frenzied Member
Re: How to delete file in use
hi everyone....
Thanx for your replies.. 
i think i couldn't make you ppl understand my problem correctly..
I have a software which generates a file and due to some bug.. it doesn't release the file after it's generated..i have made another program(in vb) which reads that file and moves that file to another folder.. now you may understand the problem.. the file which is currently in use by that software couldn't be moved by my program...
I want to know if there is a way that i could move that file to another folder...
-
Feb 17th, 2005, 11:31 PM
#7
Re: How to delete file in use
no, but the program probably did not close the file, that's why it is still open. it will close automatically when the program ends. you could go back and fix it.
if the program has the file opened, it's locked, and i don't think there is any way to move or delete it.
-
Feb 17th, 2005, 11:37 PM
#8
Re: How to delete file in use
on download.com they have stuff that does exactly this.
-
Feb 17th, 2005, 11:39 PM
#9
Re: How to delete file in use
i don't think it will delete an OPEN file. If so, send a link...
-
Feb 18th, 2005, 02:29 AM
#10
Hyperactive Member
Re: How to delete file in use
it is possible to erase an open fille or file in use as i said before is LOTS but lots of code you need to do for it and you might not find alot documentation about it since this might be used for malaware reasons you can search pscode you might find something
Born to help others
(If I've been helpful then please rate my post. Thanks)
call me EJ or be slapped! 
-
Feb 18th, 2005, 02:37 AM
#11
Re: How to delete file in use
send me a link. the closest thing to it would be to delete it when the computer boots up. Nothing that will kill a running file. Who told you that?
-
Feb 18th, 2005, 04:04 AM
#12
Re: How to delete file in use
I think you should attack thi problem from another angle. Instead of trying to move or delete the file while it is open and clearly locked. Why not end the process which owns the file and then move or delete it. A file cannot be left open by a process which has not been closed, so your other program must be leaving a process behind after its closed - sounds like a runaway thread
-
Feb 18th, 2005, 06:41 AM
#13
Thread Starter
Frenzied Member
Re: How to delete file in use
Some points..
1. I don't have the code of program which holds the file open...
2. I cannot stop the program and then delete the file, because the program is so critical that it should ALWAYS run...
3. I cannot leave the move process until the system reboots ( i know MoveFileEX API) because the program i have written pools for a file in a directory and if it finds the file it reads the file, extract some data and then (it should) move the file, and starts the pooling again... so if the file is not moved.. the pooling program will pool that again..
And let me seee... what code is that...
-
Feb 18th, 2005, 01:59 PM
#14
Re: How to delete file in use
Can you configure the program to place the file in a folder of your choosing?
-
Feb 19th, 2005, 04:40 AM
#15
Re: How to delete file in use
ok i am sure this is possible and ill explane y - btw u may only want 2 try this if u have a small tempory partition as, although it has never failed me, may cause u 2 format a partition if done incorectly
in dos u can do what is called "Kill all handles to a drive" - which basically means close all open files - the only way i know to do this is by typing FORMAT D: for example - and it will ask u if u want 2 kill all handles to the drive if any files are open - now as soon as the progress counter starts ticking up press CTRL + C to break the operation - now this wont cause any data damage to the disk as a format does nothing as far as formating the partition goes until it gets 2 100% - ironical that - lol
so you are probably wondering what takes up the remaining 99% of the format time. Well that is just used to check the partition for errors so that if bad sectors are found they are flaged as "unusable" so these bad sectors cannot be written to (if u could write to bad sectors data corruption would occur), but at this stage no actual writing occurs on the disk.
Oh - and whatever you do DONT preform a quick format as this skips the error checking stage and just clears the data on the disk!
I am not kidding above but, for leagal reasons or whatever, i would not recomend u try this unless u have a partition that u can afford to loose (even tho this wont happen).
Unfortuanatly i do not know how to close all open file handles in vb 
Kris
-
Feb 19th, 2005, 09:36 AM
#16
Thread Starter
Frenzied Member
Re: How to delete file in use
 Originally Posted by Hack
Can you configure the program to place the file in a folder of your choosing?
yah...
-
Feb 19th, 2005, 09:36 AM
#17
Thread Starter
Frenzied Member
Re: How to delete file in use
 Originally Posted by i00
ok i am sure this is possible and ill explane y - btw u may only want 2 try this if u have a small tempory partition as, although it has never failed me, may cause u 2 format a partition if done incorectly
in dos u can do what is called "Kill all handles to a drive" - which basically means close all open files - the only way i know to do this is by typing FORMAT D: for example - and it will ask u if u want 2 kill all handles to the drive if any files are open - now as soon as the progress counter starts ticking up press CTRL + C to break the operation - now this wont cause any data damage to the disk as a format does nothing as far as formating the partition goes until it gets 2 100% - ironical that - lol
so you are probably wondering what takes up the remaining 99% of the format time. Well that is just used to check the partition for errors so that if bad sectors are found they are flaged as "unusable" so these bad sectors cannot be written to (if u could write to bad sectors data corruption would occur), but at this stage no actual writing occurs on the disk.
Oh - and whatever you do DONT preform a quick format as this skips the error checking stage and just clears the data on the disk!
I am not kidding above but, for leagal reasons or whatever, i would not recomend u try this unless u have a partition that u can afford to loose (even tho this wont happen).
Unfortuanatly i do not know how to close all open file handles in vb
Kris
thanx for information...
but does this have anything to do with my problem?
-
Feb 19th, 2005, 05:10 PM
#18
Re: How to delete file in use
that's one of the most ridiculous things that I've ever heard. I assume that you haven't tried it?
-
Feb 19th, 2005, 06:05 PM
#19
Re: How to delete file in use
moinkhan it just shows that it can probably be done
and dglienna - yes i have tried it - lots of times - basically i use it when i get Pi**ed @ windows because i can't delete a file that says its 'in use' or even worse cant delete a folder that has nothing in it because it's in use
if u don't believe me enable try it on virtual pc and enable undo drives so u can revert
i new ppl wouldn't believe me on this lol - but it does work
-
Feb 19th, 2005, 06:21 PM
#20
Re: How to delete file in use
I thought that FAT's were deleted right off the bat. Just my luck if I tried it, it'd delete everything just like a quick format does. I'll keep it in mind, but i've never had a file or folder that I couldn't delete.
-
Feb 20th, 2005, 04:16 AM
#21
Re: How to delete file in use
If you think about it, all a format does is create a table on the disk, one for each sector which is used to store information about the file. I.e: whether the secotr is free / in use. If you format partition in Linux with the mkfs comamnd, this is all it does and rarely takes more than a couple of seconds.
I definatly wouldn't recommend i00's suggestion unless you back up your data first and never attempt it on an NTFS parition.
Another thing you can do is have the file located on a network share. You can then disconnect all users when you need to delete it.
-
Feb 20th, 2005, 04:43 PM
#22
Fanatic Member
Re: How to delete file in use
have u guys ever tried to use the kill command? it works for me everytime
-
Feb 20th, 2005, 04:57 PM
#23
Re: How to delete file in use
Not if the file is in use by another process. This is what the whole thread is about. The file is locked by another process.
-
Feb 20th, 2005, 05:06 PM
#24
Retired VBF Adm1nistrator
Re: How to delete file in use
It is possible to delete a file that's in use. All you have to do is close the file handle to that file.
See a blog entry of mine here. Its based on ASP.NET, but the idea's the exact same: http://www.irishdev.com/blogs/plende...12/28/401.aspx
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 21st, 2005, 02:07 AM
#25
Thread Starter
Frenzied Member
Re: How to delete file in use
 Originally Posted by plenderj
dat works with VB6?
i'll have to take a look at this..
thanx m8
-
Feb 21st, 2005, 03:40 PM
#26
Lively Member
Re: How to delete file in use
About two years ago I downloaded a small, free app from http://www.merxsoft.com/Download/Downloads.htm called ofl.exe.
It stands for Open File List. With it you can see who has a file open (on a remote server or locally) and even force them off of the file. I use it all the time when something happens and a file does not get released properly. I've never had any file corruption because of using the file.
Works great for me.
Don C
-
Feb 21st, 2005, 05:58 PM
#27
Fanatic Member
Re: How to delete file in use
it shouldnt matter if its in use or not it i had do delete a virus renamed explorer.exe and it was in use and the kill command worked fine
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|