This is a multi-part message in MIME format.

------=_NextPart_000_000E_01C4AA6D.E3ECA330
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

Hi,

The following script is supposed to rename all files start with sg and =
with extension .dat, it will remove the prefix sg from the file name. eg =
: sgtestfile.dat --> testfile.dat.

However, it is not working as expected, it returns error:
"G:\Script\Test\rename.vbs(1, 19) Microsoft VBScript compilation error: =
Expected end of statement Exit code: 1 , 0001h"

Dim strPrefix As String, strExtension As String, strPath As String=20
Dim strFilePattern As String, strstrOldName As String, strNewName As =
String=20
=20
strPrefix =3D "SG"=20
strExtension =3D "DAT"=20
strPath =3D "G:\Script\Test\"=20
=20
strFilePattern =3D strPath & strPrefix & "*." & strExtension=20
=20
Dim strFileFinder As String=20
strFileFinder =3D Dir(strFilePattern)=20
=20
Do Until strFileFinder =3D ""=20
strOldName =3D strPath & strFileFinder=20
strNewName =3D strPath & Right(strFileFinder, Len(strFileFinder) =
- Len(strPrefix))=20
Name strOldName As strNewName=20
strFileFinder =3D Dir=20
Loop=20


Can anyone help, I feel that the line "strFileFinder =3D =
Dir(strFilePattern)" is having problem.

Thanks
Frank


------=_NextPart_000_000E_01C4AA6D.E3ECA330
Content-Type: text/html;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312">
<META content=3D"MSHTML 6.00.2800.1458" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The following script is&nbsp;supposed =
to rename all=20
files start with sg and with extension .dat, it will remove the prefix =
sg from=20
the file name. eg :&nbsp; sgtestfile.dat&nbsp;--&gt; =
testfile.dat.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;However, it is not working as =
expected, it=20
returns error:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>"G:\Script\Test\rename.vbs(1, 19) =
Microsoft=20
VBScript compilation error: Expected end of statement </FONT><FONT =
face=3DArial=20
size=3D2>Exit code: 1 , 0001h"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Dim strPrefix As =
String,=20
strExtension As String, strPath As String <BR>&nbsp;&nbsp;&nbsp; Dim=20
strFilePattern As String, strstrOldName As String, strNewName As String=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; strPrefix =3D "SG"=20
<BR>&nbsp;&nbsp;&nbsp; strExtension =3D "DAT" <BR>&nbsp;&nbsp;&nbsp; =
strPath =3D=20
"G:\Script\Test\" <BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
strFilePattern =3D strPath &amp; strPrefix &amp; "*." &amp; strExtension =

<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim strFileFinder As =
String=20
<BR>&nbsp;&nbsp;&nbsp; strFileFinder =3D Dir(strFilePattern)=20
<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Do Until strFileFinder =3D =
""=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strOldName =3D strPath =
&amp;=20
strFileFinder <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strNewName =
=3D=20
strPath &amp; Right(strFileFinder, Len(strFileFinder) - Len(strPrefix))=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name strOldName As =
strNewName=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strFileFinder =3D Dir=20
<BR>&nbsp;&nbsp;&nbsp; Loop <BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Can anyone help, I feel that the=20
line&nbsp;"strFileFinder =3D Dir(strFilePattern)" is having =
problem.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Frank</DIV>
<DIV><BR></DIV></FONT></BODY></HTML>

------=_NextPart_000_000E_01C4AA6D.E3ECA330--

RE: vbs to rename files in the directory by tlavedas

tlavedas
Mon Oct 04 11:09:02 CDT 2004

Scripting only supports the Variant data type. Remove all of the AS clauses
from the Dim statements.

I didn't check the rest of the logic.

Tom Lavedas
===========

"Frank" wrote:

> Hi,
>
> The following script is supposed to rename all files start with sg and with extension .dat, it will remove the prefix sg from the file name. eg : sgtestfile.dat --> testfile.dat.
>
> However, it is not working as expected, it returns error:
> "G:\Script\Test\rename.vbs(1, 19) Microsoft VBScript compilation error: Expected end of statement Exit code: 1 , 0001h"
>
> Dim strPrefix As String, strExtension As String, strPath As String
> Dim strFilePattern As String, strstrOldName As String, strNewName As String
>
> strPrefix = "SG"
> strExtension = "DAT"
> strPath = "G:\Script\Test\"
>
> strFilePattern = strPath & strPrefix & "*." & strExtension
>
> Dim strFileFinder As String
> strFileFinder = Dir(strFilePattern)
>
> Do Until strFileFinder = ""
> strOldName = strPath & strFileFinder
> strNewName = strPath & Right(strFileFinder, Len(strFileFinder) - Len(strPrefix))
> Name strOldName As strNewName
> strFileFinder = Dir
> Loop
>
>
> Can anyone help, I feel that the line "strFileFinder = Dir(strFilePattern)" is having problem.
>
> Thanks
> Frank
>
>

Re: vbs to rename files in the directory by McKirahan

McKirahan
Mon Oct 04 12:52:54 CDT 2004

This is a multi-part message in MIME format.

------=_NextPart_000_002A_01C4AA11.0A1794A0
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

"Frank" <signup0702@sina.com> wrote in message =
news:urnsAriqEHA.3288@TK2MSFTNGP12.phx.gbl...
Hi,

The following script is supposed to rename all files start with sg and =
with extension .dat, it will remove the prefix sg from the file name. eg =
: sgtestfile.dat --> testfile.dat.

However, it is not working as expected, it returns error:
"G:\Script\Test\rename.vbs(1, 19) Microsoft VBScript compilation =
error: Expected end of statement Exit code: 1 , 0001h"

Dim strPrefix As String, strExtension As String, strPath As String =

Dim strFilePattern As String, strstrOldName As String, strNewName =
As String=20
=20
strPrefix =3D "SG"=20
strExtension =3D "DAT"=20
strPath =3D "G:\Script\Test\"=20
=20
strFilePattern =3D strPath & strPrefix & "*." & strExtension=20
=20
Dim strFileFinder As String=20
strFileFinder =3D Dir(strFilePattern)=20
=20
Do Until strFileFinder =3D ""=20
strOldName =3D strPath & strFileFinder=20
strNewName =3D strPath & Right(strFileFinder, =
Len(strFileFinder) - Len(strPrefix))=20
Name strOldName As strNewName=20
strFileFinder =3D Dir=20
Loop=20


Can anyone help, I feel that the line "strFileFinder =3D =
Dir(strFilePattern)" is having problem.

Thanks
Frank

Is "Dir()" an undeclared Subroutine or Function?

Please post in plain text!

Here's an alternative; watch for word-wrap.

Option Explicit
'*
Const cVBS =3D "renamer.vbs"
Const cPRE =3D "SG"
Const cEXT =3D "DAT"
Const cFOL =3D "G:\Script\Test\"
'*
Dim strFIL
Dim strGFI
Dim intMOV
intMOV =3D 0
'*
Dim objFSO
Set objFSO =3D CreateObject("Scripting.FileSystemObject")
Dim objGFO
Set objGFO =3D objFSO.GetFolder(cFOL)
Dim objGFI
Set objGFI =3D objGFO.Files
For Each strGFI in objGFI
strFIL =3D strGFI.Name
If UCase(Left(strFIL,Len(cPRE))) =3D cPRE _
And UCase(Right(strFIL,Len(cEXT))) =3D cEXT Then
intMOV =3D intMOV + 1
objFSO.MoveFile strGFI, Mid(strFIL,Len(cPRE)+1)
End If
Next
'*
Set objGFI =3D Nothing
Set objGFO =3D Nothing
Set objFSO =3D Nothing
'*
MsgBox intMOV & " files renamed",vbInformation,cVBS

------=_NextPart_000_002A_01C4AA11.0A1794A0
Content-Type: text/html;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312">
<META content=3D"MSHTML 5.50.4937.800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Frank" &lt;<A=20
href=3D"mailto:signup0702@sina.com">signup0702@sina.com</A>&gt; wrote =
in message=20
<A=20
=
href=3D"news:urnsAriqEHA.3288@TK2MSFTNGP12.phx.gbl">news:urnsAriqEHA.3288=
@TK2MSFTNGP12.phx.gbl</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The following script is&nbsp;supposed =
to rename=20
all files start with sg and with extension .dat, it will remove the =
prefix sg=20
from the file name. eg :&nbsp; sgtestfile.dat&nbsp;--&gt;=20
testfile.dat.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;However, it is not working as =
expected, it=20
returns error:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>"G:\Script\Test\rename.vbs(1, 19) =
Microsoft=20
VBScript compilation error: Expected end of statement </FONT><FONT =
face=3DArial=20
size=3D2>Exit code: 1 , 0001h"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Dim strPrefix As =
String,=20
strExtension As String, strPath As String <BR>&nbsp;&nbsp;&nbsp; Dim=20
strFilePattern As String, strstrOldName As String, strNewName As =
String=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; strPrefix =3D "SG" =

<BR>&nbsp;&nbsp;&nbsp; strExtension =3D "DAT" <BR>&nbsp;&nbsp;&nbsp; =
strPath =3D=20
"G:\Script\Test\" <BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
strFilePattern =3D strPath &amp; strPrefix &amp; "*." &amp; =
strExtension=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim strFileFinder =
As=20
String <BR>&nbsp;&nbsp;&nbsp; strFileFinder =3D Dir(strFilePattern)=20
<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Do Until strFileFinder =
=3D ""=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strOldName =3D strPath =
&amp;=20
strFileFinder <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
strNewName =3D=20
strPath &amp; Right(strFileFinder, Len(strFileFinder) - =
Len(strPrefix))=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name strOldName As =
strNewName=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strFileFinder =3D Dir=20
<BR>&nbsp;&nbsp;&nbsp; Loop <BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Can anyone help, I feel that the=20
line&nbsp;"strFileFinder =3D Dir(strFilePattern)" is having=20
problem.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Frank</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>Is "Dir()" an undeclared =
Subroutine or=20
Function?</STRONG></FONT></DIV>
<DIV><STRONG><FONT face=3DArial size=3D2></FONT></STRONG>&nbsp;</DIV>
<DIV><STRONG><FONT face=3DArial size=3D2>Please post in plain=20
text!</FONT></STRONG></DIV>
<DIV><STRONG><FONT face=3DArial size=3D2></FONT><FONT face=3DArial=20
size=3D2></FONT></STRONG>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here's an alternative; watch for=20
word-wrap.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Option=20
Explicit<BR>&nbsp;&nbsp; '*<BR>&nbsp;&nbsp;&nbsp; Const cVBS =3D=20
"renamer.vbs"<BR>&nbsp;&nbsp;&nbsp; Const cPRE =3D =
"SG"<BR>&nbsp;&nbsp;&nbsp;=20
Const cEXT =3D "DAT"<BR>&nbsp;&nbsp;&nbsp; Const cFOL =3D=20
"G:\Script\Test\"<BR>&nbsp;&nbsp; '*<BR>&nbsp;&nbsp;&nbsp; Dim=20
strFIL<BR>&nbsp;&nbsp;&nbsp; Dim strGFI</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Dim =
intMOV</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intMOV=20
=3D 0<BR>&nbsp;&nbsp; '*<BR>&nbsp;&nbsp;&nbsp; Dim =
objFSO<BR>&nbsp;&nbsp;&nbsp;=20
Set objFSO =3D =
CreateObject("Scripting.FileSystemObject")<BR>&nbsp;&nbsp;&nbsp;=20
Dim objGFO<BR>&nbsp;&nbsp;&nbsp; Set objGFO =3D=20
objFSO.GetFolder(cFOL)<BR>&nbsp;&nbsp;&nbsp; Dim =
objGFI<BR>&nbsp;&nbsp;&nbsp;=20
Set objGFI =3D objGFO.Files<BR>&nbsp;&nbsp;&nbsp; For Each strGFI in=20
objGFI<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strFIL =3D=20
strGFI.Name<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If&nbsp;=20
UCase(Left(strFIL,Len(cPRE))) =3D cPRE=20
_<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; And=20
UCase(Right(strFIL,Len(cEXT))) =3D cEXT Then</FONT></DIV>
<DIV><FONT face=3DArial=20
=
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;intMOV=20
=3D intMOV +=20
=
1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;objFSO.MoveFile=20
strGFI, =
Mid(strFIL,Len(cPRE)+1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
End If<BR>&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp; =
'*<BR>&nbsp;&nbsp;&nbsp; Set=20
objGFI =3D Nothing<BR>&nbsp;&nbsp;&nbsp; Set objGFO =3D=20
Nothing<BR>&nbsp;&nbsp;&nbsp; Set objFSO =3D Nothing</FONT></DIV>
<DIV><FONT face=3DArial><FONT size=3D2>&nbsp;&nbsp; =
'*</FONT></FONT></DIV>
<DIV><FONT face=3DArial><FONT size=3D2>&nbsp;&nbsp;&nbsp; MsgBox =
intMOV &amp; "=20
files renamed",vbInformation,cVBS</FONT></FONT></DIV>
<DIV><FONT face=3DArial><FONT=20
size=3D2></FONT>&nbsp;</DIV></BLOCKQUOTE></FONT></BODY></HTML>

------=_NextPart_000_002A_01C4AA11.0A1794A0--