Deleting files and folders

G

Gunnar B

I am writing a macro that shall copy files from one source structure to a target structure. Before the files are copied I want to delete all files and folders in the target structure.
I use the Kill command to delete the files in a folder and then I use the RmDir command to delete the folder. The Kill command works OK but the RmDir command results in error 75 "Path/File access error". If I restart the macro the folder that is now empty is deleted OK but when trying to delete the next folder, error 75 occurs again.
Is there a timing problem here? Is it possible to get any type of confirmation that all files have been deleted Ok before trying to delete the folder?
 
P

Perry

Set a reference to Microsoft Scripting Runtime in yr VBA project
VBE menu: Tools | References

And following code will delete the folder:

Dim fs As New FileSystemObject
Dim f As Folder
Set f = fs.GetFolder("c:\temp\test")
f.Delete

Krgrds,
Perry

Gunnar B said:
I am writing a macro that shall copy files from one source structure to a
target structure. Before the files are copied I want to delete all files and
folders in the target structure.
I use the Kill command to delete the files in a folder and then I use the
RmDir command to delete the folder. The Kill command works OK but the RmDir
command results in error 75 "Path/File access error". If I restart the macro
the folder that is now empty is deleted OK but when trying to delete the
next folder, error 75 occurs again.
Is there a timing problem here? Is it possible to get any type of
confirmation that all files have been deleted Ok before trying to delete the
folder?
 
G

Gunnar B

Hi Perry!
It worked perfectly. Thank you!!! Using this method made it almost too easy, I don't eaven have to loop to get all subfolder names. All I have to do is to simply delete the top folder!
This "Microsoft Scripting Runtime" was something new to me. It seems to be very powerful, how can I learn more about it?
Regards
Gunnar

----- Perry wrote: -----

Set a reference to Microsoft Scripting Runtime in yr VBA project
VBE menu: Tools | References

And following code will delete the folder:

Dim fs As New FileSystemObject
Dim f As Folder
Set f = fs.GetFolder("c:\temp\test")
f.Delete

Krgrds,
Perry
 
P

Perry

The information for FileSystemObject isn't available
in yr VBE help.

In such case, jump to the online MS help:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/ht
ml/sgprogrammingfilesystemobject.asp

Krgrds,
Perry

Gunnar B said:
Hi Perry!
It worked perfectly. Thank you!!! Using this method made it almost too
easy, I don't eaven have to loop to get all subfolder names. All I have to
do is to simply delete the top folder!
This "Microsoft Scripting Runtime" was something new to me. It seems to be
very powerful, how can I learn more about it?
 

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