Results 1 to 27 of 27

Thread: How to delete file in use

  1. #1

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    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..

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How to delete file in use

    What kind of file is it and how is it in use by the other process?

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to delete file in use

    Quote 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.

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How to delete file in use

    Quote 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...

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to delete file in use

    Quote 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.

  6. #6

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    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...

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  8. #8
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: How to delete file in use

    on download.com they have stuff that does exactly this.

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How to delete file in use

    i don't think it will delete an OPEN file. If so, send a link...

  10. #10
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367

    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!

  11. #11
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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?

  12. #12
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  13. #13

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    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...

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to delete file in use

    Can you configure the program to place the file in a folder of your choosing?

  15. #15
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    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

  16. #16

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: How to delete file in use

    Quote Originally Posted by Hack
    Can you configure the program to place the file in a folder of your choosing?
    yah...

  17. #17

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: How to delete file in use

    Quote 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?

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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?

  19. #19
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    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

  20. #20
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  21. #21
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  22. #22
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Thumbs up Re: How to delete file in use

    have u guys ever tried to use the kill command? it works for me everytime

  23. #23
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  24. #24
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    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]

  25. #25

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: How to delete file in use

    Quote Originally Posted by plenderj
    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
    dat works with VB6?
    i'll have to take a look at this..
    thanx m8

  26. #26
    Lively Member
    Join Date
    May 2002
    Location
    Minnesota
    Posts
    91

    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
    Stumbler

  27. #27
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    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
  •  



Click Here to Expand Forum to Full Width