calling a vbs from a .BAT to rename a file by adding a dot 
Author Message
 calling a vbs from a .BAT to rename a file by adding a dot

hi,

I need to rename files from original name with 3 numbers at the end
(e.g.. a5225s325) to name.3numbers (e.g.. a5225s.325).
I wasn't able to do that in dos programming. i would like to call a
vbs program from a .BAT.
Can any one tell me :
  1. how to call the vbs from the .bat (whith the file name in
parameter)
  2. what's the syntaxe in the vbs (sorry i'm a newbie)

I use window NT4
thks for help



Sun, 03 Apr 2005 23:02:44 GMT  
 calling a vbs from a .BAT to rename a file by adding a dot

Quote:

> hi,

> I need to rename files from original name with 3 numbers at the end
> (e.g.. a5225s325) to name.3numbers (e.g.. a5225s.325).
> I wasn't able to do that in dos programming. i would like to call a
> vbs program from a .BAT.
> Can any one tell me :
>   1. how to call the vbs from the .bat (whith the file name in
> parameter)
>   2. what's the syntaxe in the vbs (sorry i'm a newbie)

If you files are of the format "a????s???.", then no need for WSH on this
occasion:-

for %%a in ("a????s???.") Do set f=%%~na&call ren "%%a" "%%f:~0,6%%.%%f:~6,3%%"

--
Ritchie
Undo address for mail



Sun, 03 Apr 2005 23:32:08 GMT  
 calling a vbs from a .BAT to rename a file by adding a dot

Quote:
>  1. how to call the vbs from the .bat (whith the file name in
>parameter)

If your VBS file is c:\folder\myscript.vbs and you want the file
a5225s325 as the parameter, you enter this into your batch file:

cscript c:\folder\myscript.vbs a5225s325

There is another trick if you want the VBS to return data to the batch
file, you can have the VBS echo it to standard out, and capture it
like this (single line):

for /F %%n in ('cscript c:\folder\myscript.vbs a5225s325') do set
data=%%n

Quote:
>  2. what's the syntaxe in the vbs (sorry i'm a newbie)

If you want the VBS to rename the file, the VBS file could look like
this:

option explicit
Dim fso, File, NewName
Set fso = CreateObject("Scripting.FileSystemObject")
Set File = fso.GetFile(wscript.Arguments(0))
NewName = Left(File.Name,Len(File.Name)-3) & "." & Right(File.Name, 3)
File.Name = NewName

If you want to use the second trick above, replace the last line with:

wscript.echo NewName

... and issue a REN command in the batch file like this:

REN a5225s325 %data%

--
Helge Wunderlich
(Please remove the spam trap if you wish to send email)



Mon, 04 Apr 2005 15:08:57 GMT  
 calling a vbs from a .BAT to rename a file by adding a dot
thks for the script, it works well
Quote:
>-----Original Message-----


>>  1. how to call the vbs from the .bat (whith the file
name in
>>parameter)

>If your VBS file is c:\folder\myscript.vbs and you want
the file
>a5225s325 as the parameter, you enter this into your
batch file:

>cscript c:\folder\myscript.vbs a5225s325

>There is another trick if you want the VBS to return data
to the batch
>file, you can have the VBS echo it to standard out, and
capture it
>like this (single line):

>for /F %%n in ('cscript c:\folder\myscript.vbs
a5225s325') do set
>data=%%n

>>  2. what's the syntaxe in the vbs (sorry i'm a newbie)

>If you want the VBS to rename the file, the VBS file
could look like
>this:

>option explicit
>Dim fso, File, NewName
>Set fso = CreateObject("Scripting.FileSystemObject")
>Set File = fso.GetFile(wscript.Arguments(0))
>NewName = Left(File.Name,Len(File.Name)-3) & "." & Right
(File.Name, 3)
>File.Name = NewName

>If you want to use the second trick above, replace the
last line with:

>wscript.echo NewName

>.... and issue a REN command in the batch file like this:

>REN a5225s325 %data%

>--
>Helge Wunderlich
>(Please remove the spam trap if you wish to send email)
>.



Mon, 04 Apr 2005 19:22:18 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Calling VBS from BAT file?

2. Add computer in domain with vbs or tools call by vbs

3. Calling *.vbs files to Run From Master VBS File

4. how to call vbs file from vbs file

5. Running DOS BAT file from VBS file

6. Calling BAT files

7. passing variables from .bat files to .vbs scripts

8. .bat file to launch .vbs

9. Ben?tige Hilfe im Bereich Bat oder VBS File

10. Calling a .vbs file from another vbs

11. bats bats bats halloween

12. Rename file using VBS

 

 
Powered by phpBB® Forum Software