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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FSO - Delete Files 2

Status
Not open for further replies.

vbmorton

Technical User
Dec 27, 2004
44
US
Hi all.

What I am trying to do is, Create a folder and enter documents into that folder.

I am doing this.

fso.CreateFolder (fldr & "\" & Trim$(rsT(2)))

Sometimes this folder is already out there. so.. it goes into my error handling.

then in my error handling:

Select Case Err.Number

Case 58
Resume Next ' folder already exits

Here is where I want to say. Keep the folder, but delete all the files in it so that i can repopulate the folder.

Any ideas of how that might look here??


Thanks

VBMORTON
 
Just use the FolderExists property of the fso to check if the folder exists already. Then delete the files or the folder if you want.
-Max
 
This should be pretty close.

Code:
dim strFolder as string
dim oFile as Scripting.File

strFolder = fldr & "\" & Trim$(rsT(2))

If fso.FolderExists(strFolder) then
  For Each oFile In fso.GetFolder(strFolder).Files
    oFile.Delete
  Next
else
  Call fso.CreateFolder(strFolder)
End If

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top