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

Deleting Files 1

Status
Not open for further replies.

tdonahue

Technical User
Feb 4, 2001
50
0
0
US
I am trying to write a function that will delete all the files in a directory. I got a delete program from the FAQ section. The only problem with it is it only deletes one file at a time. I need it to delete 24 files.
The problem is the function will only delete the last file in my group. What can I do to make my program loop to delete all the programs?

My code is as follows:

Function DeleteFile()
Dim fso
Dim file As String
'file = "C:\My Data\Eracent\Audit File\My Documents" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\My Documents" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_AIXModels_LUT" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_BS_LUT" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_pa_lut" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_Packages.fmt" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_Packages.txt" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_PAR_LUT" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_PkgType_LUT.txt" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_POR_LUT" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_POR_LUT.txt" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_Processor_LUT" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_ProductProcess_LUT" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_ProductProcess_LUT.txt" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_SMBSPN_LUT" ' change to match the file w/Path
'file = "C:\My Data\Eracent\Audit File\T_SMBSPV_LUT" ' change to match the file w/Path"
'file = "C:\My Data\Eracent\Audit File\T_SNMPMakes_LUT" ' change to match the file w/Path"
'file = "C:\My Data\Eracent\Audit File\T_SNMPModels_LUT" ' change to match the file w/Path"
'file = "C:\My Data\Eracent\Audit File\T_SWMfg.txt" ' change to match the file w/Path"
'file = "C:\My Data\Eracent\Audit File\T_SWProducts.fmt" ' change to match the file w/Path"
'file = "C:\My Data\Eracent\Audit File\T_SWProducts.txt" ' change to match the file w/Path"
'file = "C:\My Data\Eracent\Audit File\T_UFPAR_LUT" ' change to match the file w/Path"
'file = "C:\My Data\Eracent\Audit File\T_UPAR_LUT" ' change to match the file w/Path"
'file = "C:\My Data\Eracent\Audit File\Update.exe" ' change to match the file w/Path"

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(file) Then
fso.DeleteFile file, True
Else
MsgBox file & " does not exist or has already been deleted!" _
, vbExclamation, "File not Found"
End If
End Function

Tom
 
Try this:
Code:
Function DeleteFile()
Dim fso
dim fCounter As Integer
Dim file(24) As String
file(1) = "C:\My Data\Eracent\Audit File\My Documents" ' change to match the file w/Path
file(2) = "C:\My Data\Eracent\Audit File\My Documents" ' change to match the file w/Path
file(3) = "C:\My Data\Eracent\Audit File\T_AIXModels_LUT" ' change to match the file w/Path
file(4) = "C:\My Data\Eracent\Audit File\T_BS_LUT" ' change to match the file w/Path
file(5) = "C:\My Data\Eracent\Audit File\T_pa_lut" ' change to match the file w/Path
file(6) = "C:\My Data\Eracent\Audit File\T_Packages.fmt" ' change to match the file w/Path
file(7) = "C:\My Data\Eracent\Audit File\T_Packages.txt" ' change to match the file w/Path
file(8) = "C:\My Data\Eracent\Audit File\T_PAR_LUT" ' change to match the file w/Path
file(9) = "C:\My Data\Eracent\Audit File\T_PkgType_LUT.txt" ' change to match the file w/Path
file(10) = "C:\My Data\Eracent\Audit File\T_POR_LUT" ' change to match the file w/Path
file(11) = "C:\My Data\Eracent\Audit File\T_POR_LUT.txt" ' change to match the file w/Path
file(12) = "C:\My Data\Eracent\Audit File\T_Processor_LUT" ' change to match the file w/Path
file(13) = "C:\My Data\Eracent\Audit File\T_ProductProcess_LUT" ' change to match the file w/Path
file(14) = "C:\My Data\Eracent\Audit File\T_ProductProcess_LUT.txt" ' change to match the file w/Path
file(15) = "C:\My Data\Eracent\Audit File\T_SMBSPN_LUT" ' change to match the file w/Path
file(16) = "C:\My Data\Eracent\Audit File\T_SMBSPV_LUT" ' change to match the file w/Path"
file(17) = "C:\My Data\Eracent\Audit File\T_SNMPMakes_LUT" ' change to match the file w/Path"
file(18) = "C:\My Data\Eracent\Audit File\T_SNMPModels_LUT" ' change to match the file w/Path"
file(19) = "C:\My Data\Eracent\Audit File\T_SWMfg.txt" ' change to match the file w/Path"
file(20) = "C:\My Data\Eracent\Audit File\T_SWProducts.fmt" ' change to match the file w/Path"
file(21) = "C:\My Data\Eracent\Audit File\T_SWProducts.txt" ' change to match the file w/Path"
file(22) = "C:\My Data\Eracent\Audit File\T_UFPAR_LUT" ' change to match the file w/Path"
file(23) = "C:\My Data\Eracent\Audit File\T_UPAR_LUT" ' change to match the file w/Path"
file(24) = "C:\My Data\Eracent\Audit File\Update.exe" ' change to match the file w/Path"

Set fso = CreateObject("Scripting.FileSystemObject")
For fCounter = 1 to 24
    If fso.FileExists(file(fCounter)) Then
        fso.DeleteFile file(fCounter), True
    Else
        MsgBox file(fCounter) & " does not exist or has already been deleted!" _
            , vbExclamation, "File not Found"
    End If
Next fCounter
End Function
 
Thanks !

This was the exact solution I needed.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top