Can I use VB:s string.StartsWith in WScript? How?

Posted on 2009-05-14
Last Modified: 2012-05-07

I have a script that I use to check folders for files using scheduled tasks.
If it finds files, it moves them to a sub folder and then alerts a user with an email.

I now have a few macs that access this file system and thus I have a lot of files starting with a "."

I'd like this script to automatically remove them.

As a java programmer, the logical choice was to search for a starts with function.
I found one in VB script, but I can not seem to get it to work.

Code below. The currentFileName echoes correctly, but when I try to use:
currentFileName.StartsWith(".") - I get a 800A01A8 error "object required".

Code below. (Commented out the actual moving and deleting of files + emailing for testing)

Many thanks in advance, and best regards,

Option Explicit

Dim Fso, args, num, folderPath, utrPath, strEmailFrom, strEmailTo, strEmailSubject, strSMTP, sendMail, strFilesInBody, currentFileName, myFolder, filecount, colFiles, foundFile

Set Fso = CreateObject("Scripting.FileSystemObject") 

Set args = WScript.Arguments

num = args.Count

if num < 3 then

   WScript.Echo "Du glömde ange parameter för mapp att kolla och/eller mottagarens mejladress och/eller meddelande." & vbCrLf & "Används: scriptnamn.vbs C:\Temp Meddelande" & vbCrLf & "Eventuella extra e-postadresser, lägg till ; mellan." & vbCrLf & "Ex:;"

   WScript.Quit 1

end if

folderPath = args.Item(0)

utrPath = folderPath & "\utredning\"

strEmailFrom = ""

strEmailTo = args.Item(1)

strEmailSubject = "*** LARM *** " & args.Item(2)

strSMTP = ""

sendMail = 0

strFilesInBody = ""

currentFileName = ""

Set myFolder = Fso.GetFolder(folderPath)

filecount = myFolder.Files.Count

Set colFiles = myFolder.Files

For Each foundFile In colFiles

	Set currentFileName = Fso.GetFileName(foundFile)

	If currentFileName.StartsWith(".") Then

		WScript.echo "yes"

	End If


    If Len(Fso.GetExtensionName(foundFile)) <= 3 Then

		WScript.echo currentFileName

		'strFilesInBody = strFilesInBody +  currentFileName & vbCrLf

		'sendMail = 1

		'Fso.CopyFile foundFile, utrPath, true



		WScript.echo currentFileName

		'Rensa mac-filer

		'filecount = filecount -1


	End If


strEmailBody = "Nu ligger det " & filecount & " filer i " & utrPath & vbCrLf & vbCrLf & strFilesInBody

Set objEmail = CreateObject("CDO.Message")

objEmail.From = strEmailFrom

objEmail.To = strEmailTo

objEmail.Subject = strEmailSubject

objEmail.Textbody = strEmailBody

objEmail.Configuration.Fields.Item _

    ("") = 2

objEmail.Configuration.Fields.Item _

    ("") = _


objEmail.Configuration.Fields.Item _

    ("") = 25


If sendMail > 0 Then


End If

WScript.Quit 0

Open in new window

Question by:larsan
LVL 10

Accepted Solution

Marcjev earned 500 total points
ID: 24392906
Remark: The GetFileName method returns a string and no object. Hence it has no methods in vbscript
You should write something like:
var currentFileName, firstchar
currentFileName = Fso.GetFileName(foundFile)
firstchar = left(currentfilename,1)

Or use some other string functions (search for vbscript string functions on the web)


Author Closing Comment

ID: 31581814

In java-lingo a string is an object so I assumed that it was so in vb.

The code below works nicely:

currentFileName = Fso.GetFileName(foundFile)
firstChar = Left(currentFileName,1)
If StrComp(firstChar,".",1) = 0 Then ...

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate ( First, just open a new email message. In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now