Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How Do You Delete Files And Folders With Visual Basic Script (VBS)?

0
Posted

How Do You Delete Files And Folders With Visual Basic Script (VBS)?

0

This will give an example of how to create a Visual Basic script that will delete a file and folder. Open a plain text editor like Notepad.exe. Copy and paste the text below into your plain text document. ‘================= On Error Resume Next Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim fldr1, FileName1, FileName2 Set wshShell = WScript.CreateObject(“WScript.Shell”) Set fso = CreateObject(“Scripting.FileSystemObject”) ‘Set Folder path to be deleted ‘This can be replaced by using the command line parameter method described in a later article. fldr1 = “C:\goober” ‘Set ini file names FileName1 = “C:\goober\goober.ini” FileName2 = “C:\goober\whataname.INI” ‘Call Subs to cleanup DeleteFolder (fldr1) DeleteFile (FileName1) DeleteFile (FileName2) Function DeleteFolder(FldrPath) If (fso.FolderExists(FldrPath)) then fso.DeleteFolder(FldrPath), True End If End Function Function DeleteFile(File) If (fso.FileExists(File)) then fso.DeleteFile(File), True End If End Function ‘=======

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123