PDA

View Full Version : Delete all files in a directory



dgoff1228
07-08-2009, 08:24 AM
I have a problem that used to work in Excel using VBA to locate and delete all of my files that I stored on my sharepoint site. I have a spreadsheet that creates all the data I need and saves it to a sharepoint drive as htm files. I delete the old one first so not to use up to much space. This used to work but now I can't get it to map to the directory. I used say it worked when we have Office 2003 , now we have Office 2007.

the files are all located on

https://spsf05.web.att.com/sites/IWT-RSR/APRIL2008/Current/default.aspx

and I would map to

https://spsf05.web.att.com/sites/IWT-RSR/APRIL2008/Current/Shared Documents/

loop and delete any *.htm files using the Kill command using

If Len(Dir$(Killfile)) > 0 Then
SetAttr Killfile, vbNormal
Kill Killfile
End If
End Sub
Sub DeleteOldFiles(DrivePath)

Dim MyFile As String
Dim fs, drive, source, drivetype
Set fs = CreateObject("Scripting.FileSystemObject")
Set drive = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(DrivePath)))
MyFile = Dir$(DrivePath + "*.htm")
If MyFile <> "" Then
MyFile = Dir$(DrivePath + "*.htm")
End If
Do While MyFile <> ""
Kill DrivePath & "*.htm"
KillProperly DrivePath & MyFile
MyFile = Dir$(DrivePath + "*.htm")
Loop
End Sub

Now I get a bad file error and I can not delete any of the files. I can save to the file as I did before. But I want to delete any files out there first.


Thanks for any help.

David