PC Review


Reply
Thread Tools Rate Thread

deleting files using kill statement

 
 
toddr
Guest
Posts: n/a
 
      23rd Sep 2008
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?
 
Reply With Quote
 
 
 
 
BeWyched
Guest
Posts: n/a
 
      23rd Sep 2008
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



"toddr" wrote:

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

 
Reply With Quote
 
GeoffG
Guest
Posts: n/a
 
      23rd Sep 2008
> 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





"toddr" <(E-Mail Removed)> wrote in message
news:68F838EC-537E-41FC-BF7B-(E-Mail Removed)...
>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?



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kill statement fails c mateland Microsoft Powerpoint 9 9th Aug 2005 04:47 AM
Kill Statement Bob Microsoft Access VBA Modules 2 25th Apr 2004 10:52 PM
Kill Statement Steve Microsoft Access Form Coding 12 15th Sep 2003 06:31 AM
Kill Statement Steve Microsoft Access Getting Started 12 15th Sep 2003 06:31 AM
Kill statement Tim Microsoft Access VBA Modules 2 9th Aug 2003 02:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:07 AM.