Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use VBA to Delete A file in a certian folder (txt file)? 2

Status
Not open for further replies.

jsmokey

Technical User
Aug 19, 2005
10
US
Hi,
I was wondering if there is any way to open a certian folder on the hard drive and delete all of the files in that folder, then close the folder. Is this possible to do with vba? I know in VB6 you can do this but you have to create a filesystemobject or something. I cant figure out how to do this in vba and i was wondering if there is anyone out there who knows how to do this.

Thanks guys (and gals)
 
you can do this using the same FileSystemObject that you would use in VB6. I'm sure that a search of this forum for 'FileSystemObject' should get you started.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Easier than using the FileSystemObject ...

from Microsoft VBA Help

Deletes files from a disk.

Syntax

Kill pathname

The required pathname argument is a string expression that specifies one or more file names to be deleted. The pathname may include the directory or folder, and the drive.

Remarks

Kill supports the use of multiple-character (*) and single-character (?) wildcards to specify multiple files.

An error occurs if you try to use Kill to delete an open file.

Note To delete directories, use the RmDir statement.

Hope this helps.

 
Nice. That is easier. :)

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top