Empty out files in VBS

As part of our replication setup from SQL Server to Oracle, when we initially create a snapshot, we manually empty out all idx, sch and pre files. This is because we setup the oracle environment ourselves and dont want to use the microsoft generate code as it would cause the snapshot to fail.

I Needed a script to quickly clear out all IDX, SCH & PRE files, so made this in VBS this morning.

Dim objFSO Dim strDirectory Set objFSO = CreateObject("scripting.filesystemobject") strDirectory = "C:\VBS" CheckFolder (objFSO.getfolder(strDirectory)) '============================================================================ Sub CheckFolder(objCurrentFolder) Const ForWriting = 2 Dim objFile Dim stridx Dim strpre Dim strsch Dim strTemp stridx = ".idx" strpre = ".pre" strsch = ".sch" For Each objFile In objCurrentFolder.Files strTemp = Right(objFile.Name, 4) If UCase(strTemp) = UCase(stridx) or UCase(strTemp) = UCase(strpre) or UCase(strTemp) = UCase(strsch) Then Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(objFile.Name, ForWriting) objFile.Write "" objFile.Close End If Next End Sub '============================================================================

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: