Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Script to Delete file with exclusions

$
0
0

We have a requirement to delete all .xls file in a drive apart from certain file with name as Team.xls and Corporate.xls

I have got a script but this is creating all files. I am testing by creating a folder and creating several .xls file in that folder. The files with name  Team.xls and Corporate.xls are also available. But this is deleting all files in that folder

==============================================================================

Dim fldPath, FSO, File, Folder, filExt

Set FSO = CreateObject("Scripting.FileSystemObject")
fldPath = "D:\Test_Delete"

Set Folder = FSO.GetFolder(fldPath)

For Each File In Folder.Files
If Right(File.name, 4) = "Team.xls" Or Right(File.name, 4) = "Corporate.xls" Then
Wscript.echo "Files Present"
Else
        FSO.DeleteFile(fldPath & "\" & File.name)
    End If
Next

MsgBox "Finished..."

===========================================================================


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>