Results 1 to 12 of 12

Thread: How do I delete a file that is in use?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229

    How do I delete a file that is in use?

    I would like to delete a file that is in use! Forceful deletion in other words. Thank you in advance.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I don't think you can.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229
    U SURE? I've seen it before. Well, I'd like to delete my app after it's done, how would i do that?

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    There's been a couple of threads about this,but I forget the exact solution. I think you have to create a batch file that will delete the app and when you unload the program, shell the batch file.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    batch file was going to be my suggestion, too. There's no way to kill a file while it's running. Windows simply wont allow it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229
    lol that's what you all think. I think I know a trick around this. You make an API timer, and execute it to run in 1 second and u shut down your APP. This timer will delete your app and then end itself!

  7. #7
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Boy is my face red!

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  8. #8
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    but won't the timer end when the app ends? and if it doesn't, then that must mean the app is still running, that means you can't delete it.

    here is the batch version for self delete:

    VB Code:
    1. Private Sub Command1_Click()
    2. Open Replace(App.Path & "\Del.bat", "\\", "\") For Output As #1
    3. Print #1, "@Echo off"
    4. Print #1, ":S"
    5. Print #1, "Del " & App.EXEName & ".exe"
    6. Print #1, "If Exist " & App.EXEName & ".exe" & " goto S"
    7. Print #1, "Del Del.bat"
    8. Close #1
    9. Shell "Del.bat", vbHide
    10. Unload Me
    11.  
    12. End Sub

    use that code to unload. for example press the command button and both the app and the bat file will be deleted.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  9. #9
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    whil you cannot delete the file which is in use, you can instruct the OS to delete it upon next reboot.
    In Win NT series you need to use the MoveFileEx api call, while on Win 9X series you need to create a entry into the Wininit.ini file.

  10. #10
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Attached is a module that will delete an exe when the exe unloads.
    Attached Files Attached Files

  11. #11
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    to be honest, ur only way is to write VxDs, which VB isn't capable
    of. VxD may get the opened handler, retrieve the filename,
    intercept the file manipulation, then force deletion.

    You must have a good knowledge in ASM and device driver
    programming.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  12. #12
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by MarkT
    Attached is a module that will delete an exe when the exe unloads.
    that is basically what i had up there, but longer.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

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