deleting files using kill statement

T

toddr

i have some code that deletes image files from a network folder. the code
lists the contents of the folder to a file, reads thru and uses the kill
statement to delete them. once all the files have been removed i want to use
the RmDir command to get rid of the folder. the problem seems to be that the
folder sometimes will contain a Thumbs.db file. the Thumbs.db file does not
seem to get deleted in the code. i have tried Kill (path & "*.*") and Kill
(path & "thumbs.db") and get an error. I also get an error when i try to use
the RmDir when the thumbs.db file is still in there. If i delete manually
using windows explorer it works file.

Is this because the Thumbs.db is a system file? If so, is there a way to
delete system files using code? Anyone?
 
B

BeWyched

Hi

I don't know the answer to your question but I did have a similar problem
when trying to move files into a compressed folder. In Windows Explorer it
all worked fine, but the VBA coding failed. I think the problem was caused by
local users only having 'Read Only' rights to the files. I solved it by using
FileSystemObject rather than the direct VBA commands. This seemed to get
around the permissions issue. In your case the 'DeleteFile' and/or
'DeleteFolder' methods might work - search VBA Help for filesysytemobject +
DeleteFolder + DeleteFile.

The problem you might find though is that some Systems Admins turn off the
availability of filesystemobject as it can reprsent a security risk.

Good luck.

BW
 
G

GeoffG

Is this because the Thumbs.db is a system file?

It's because it's a hidden file.
If so, is there a way to delete system files using code?

You can delete hidden files using code, as follows:

1. Use the Tools > References menu in the VBA editor to set a reference to
Microsoft Scripting Runtime.

2. Create an object variable as follows:

Dim objFSO As Scripting.FileSystemObject
Set objFSO = New Scripting.FileSystemObject

3. Use the following methods as appropriate:

objFSO.DeleteFile
objFSO.DeleteFolder

4. If you need to test for the existence of a file or folder, use these
methods, which return a Boolean (True/False) value:

objFSO.FileExists
objFSO.FolderExists

5. You could loop through all files in a folder using VBA's Dir function.
The Dir function returns a zero-length string when it can't find any more
files. You would need a second loop using the vbHidden constant with the
Dir function to pick up hidden files.

I think this Newsgroup may only be intended for dao/vba questions, but hope
the above helps.

Geoff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top