Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > Vbscript - delete locked files
 

Vbscript - delete locked files

Hi,

I want delete all files in a folder, but I get access denied as the file is locked.

I use an email function before i'm trying to delete the files, the send email is a built in function of the application:
fcMailer.SendMailWithAttachment Process.Company, "email", Subj, "Bo", "e:\upload\test.xls"

i tried to set it to nothing: set fcMailer = nothing and set fcMailer.SendMailWithAttachment = nothing

I'm using the below to delete the files

[code]

Const DeleteReadOnly = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("e:\upload\*.*"), DeleteReadOnly

[/code]

How do i remove connection holding the file or simply just delete all locked files / or not locked

Please Assist!

Ismailc  Thursday, November 19, 2009 10:22 AM

Hi Ismailc,

The following articles describes detailed explanation and instruction: How to delete undeletable orlocked file?
http://www.geeksaresexy.net/2007/06/04/how-to-delete-an-undeletable-file/
http://www.howtohaven.com/system/deleteundeletablefiles.shtml


The main reason behind this whywe usually cannot delete locked files, is that the explorer.exe process locks files that are in use, effectively preventing you from deleting them. Usually, these files should not be touched, but sometimes, situations arise when you really need to erase some troublesome ones.

Fortunately, here are a few solutions to delete locked files, you can try to integrate into your program programmically.
Solution #1: Kill explorer.exe
Solution #2: Use The Windows Recovery Console
Solution #3: Use unlocker

By the way, for VBScript questions, you will get better support at related forums to VBScript.
http://www.visualbasicscript.com/ (A Non-Microsoft Site)
http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.scripting.vbscript VBScript Newsgroup Discussion


Best regards,
Martin Xie


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
a

Martin Xie - MSFT  Friday, November 20, 2009 10:39 AM

Hi Ismailc,

The following articles describes detailed explanation and instruction: How to delete undeletable orlocked file?
http://www.geeksaresexy.net/2007/06/04/how-to-delete-an-undeletable-file/
http://www.howtohaven.com/system/deleteundeletablefiles.shtml


The main reason behind this whywe usually cannot delete locked files, is that the explorer.exe process locks files that are in use, effectively preventing you from deleting them. Usually, these files should not be touched, but sometimes, situations arise when you really need to erase some troublesome ones.

Fortunately, here are a few solutions to delete locked files, you can try to integrate into your program programmically.
Solution #1: Kill explorer.exe
Solution #2: Use The Windows Recovery Console
Solution #3: Use unlocker

By the way, for VBScript questions, you will get better support at related forums to VBScript.
http://www.visualbasicscript.com/ (A Non-Microsoft Site)
http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.scripting.vbscript VBScript Newsgroup Discussion


Best regards,
Martin Xie


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
a

Martin Xie - MSFT  Friday, November 20, 2009 10:39 AM

You can use google to search for other answers

Custom Search

More Threads

• Setting an Object Property Value Using a Variable
• How to have Curved sides on the outside of the form
• OLE file extraction from .doc file
• Compare two text files
• Joining Access files correctly
• CompileExecutable function. Anyone got it working please?
• Concentation
• Controlling Compiler Warnings
• My.Settings and Hashtable
• Gif file not visible at runtime in vb.net 2005