Help with VBScript

Other related stuff

Help with VBScript

Unread postby gurutech » 22 Dec 2015, 21:28

I have a script that I wrote a while ago that will convert path names from a Windows format to a Linux format (ie. from using \\server\share\path to /mount/path), and it works fine.

I have found the need to create a script to do the exact opposite of this (to go from Linux to Windows), so that I can basically convert all of my 5.x Madsonic playlists (which I run on Linux) to 6.x format (which I run on Windows).

The problem I am having is that when I run the "batch" file, I get a subscript error on line 8, character 1. I think the issue is with how the parameters are being passed to the actual script.

Here is the script that I'm using:
Code: Select all
'usage: cscript replace.vbs Filename "StringToFind" "stringToReplace"
 
Option Explicit
Dim fso,strFilename,strSearch,strReplace,objFile,oldContent,newContent
 
strFilename=WScript.Arguments.Item(0)
strSearch=WScript.Arguments.Item(1)
strReplace=WScript.Arguments.Item(2)
 
'Does file exist?
Set fso=CreateObject("Scripting.FileSystemObject")
if fso.FileExists(strFilename)=false then
   cscript.echo "file not found!"
   cscript.Quit
end if
 
'Read file
set objFile=fso.OpenTextFile(strFilename,1)
oldContent=objFile.ReadAll
 
'Write file
newContent=replace(oldContent,strSearch,strReplace,1,-1,0)
set objFile=fso.OpenTextFile(strFilename,2)
objFile.Write newContent
objFile.Close


This script works perfectly if I manually type the command in the format listed in the first line, however if I run this command from the batch file I created, I get the subscript error.

Here is the batch file I created (and keep in mind, this batch file works fine if I want to convert from windows format to linux format).
Code: Select all
@echo off
D:
cd \allshared\Media\6xPlaylists
for %%A in ("*.m3u8") DO cscript //nologo //X fixlist.vbs "%%A" "
/media/Music" "\\server\share\Media\Music"
for %%A in ("*.m3u8") DO cscript //nologo //X fixlist.vbs "%%A" "/" "\"


Can anyone see what's wrong here?

Thanks!
gurutech
Contributor
Contributor
 
Posts: 323
Joined: 02 Jan 2013, 04:56
Has thanked: 12 times
Been thanked: 130 times

Return to Off Topic

Who is online

Users browsing this forum: No registered users and 2 guests