[VBScript] Check text string contains only numbers/certain character sets

Soldato
Joined
25 Mar 2004
Posts
15,983
Location
Fareham
Greetings guys

I am looking to find a way to check if a text string contains only numbers, I am writing a script that will go through all subfolders in a specified folder and check the name of the folder in order to delete older ones.

At the moment the folder contains one folder labelled for each day in the format YYYYMMDD, for example:

20090923
20090922
20090921

The script below will return a text string value for each folder name (the last 8 characters only) and the date the folder was created.

Code:
LogFilePath = "D:\Program Files\Research In Motion\BlackBerry Enterprise Server\Logs\"

Set objFSO = createobject("Scripting.filesystemobject")

Set ObjFolder = objFSO.getfolder(LogFilePath)
Set ObjFolders = objFolder.SubFolders

	For each Folder in ObjFolders

		FolderName = Right(Folder, 8)
		FolderDateCreated = Folder.DateCreated

		wscript.echo FolderName
		wscript.echo ""
		wscript.echo FolderDateCreated
				
	Next

This is my problem: I need to make sure the FolderName only contains numbers so that I don't delete the wrong folders. The folders in the folder are 95% log files that can be deleted, but there are a couple of others such as "webserver" and "installer" that I don't want the script to touch.

I was thinking of using Regular Expressions to check this but don't know how to use them properly, can anyone advise how to achieve this or give me an example using Regular Expressions?

Thanks!
 
Seems to work like a charm, this is my final script for anyone who is interested :)

Code:
'Sets the log file path
LogFilePath = "D:\Program Files\Research In Motion\BlackBerry Enterprise Server\Logs\"

'File System Object enable
Set objFSO = createobject("Scripting.filesystemobject")

'Find the subfolders
Set ObjFolder = objFSO.getfolder(LogFilePath)
Set ObjFolders = objFolder.SubFolders

'loop through the subfolders
For each Folder in ObjFolders

	'Define foldername and date created variables
	FolderName = Right(Folder, 8)
	FolderDateCreated = Folder.DateCreated

	'Verify if the foldername contains numerics or not
	If IsNumeric(FolderName) = true then

		'If folder was created more than 30 days ago delete it
		If Folder.DateCreated < Now - 30 then
	
			Folder.Delete

		End If

	End If

'Clear variables
Foldername = ""
FolderDateCreated = ""

Next
 
Back
Top Bottom