• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Newbie question: replace multiple strings in multiple text files

F

FenderAxe

#1
Hi there --

I've never created a script before now, and what I want to do is
periodically have a script go into fifteen text files and do multiple
search and replaces in each file. Ideally this would happen automatically,
such as one time per day.

I tested the example code from
http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0208
..mspx (Hey Scripting Guy) that performs one search and replace in one text
file:

*******Begin example*********

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "Jim ", "James ")

Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close

*******End example*********

This works fine for my purposes, however I need the script to perform 15
search and replace operations on the file.

Can I accomplish this just by repeating the following line with different
values?::

strNewText = Replace(strText, "Jim ", "James ")

Or is there something else I need to do to have multiple replace operations
performed?

Thanks for any advice you can provide.

FA
 

My Computer

R

Richard Mueller [MVP]

#2
See comment inline below:

"FenderAxe" <[email protected]> wrote in message
news:[email protected]

> Hi there --
>
> I've never created a script before now, and what I want to do is
> periodically have a script go into fifteen text files and do multiple
> search and replaces in each file. Ideally this would happen automatically,
> such as one time per day.
>
> I tested the example code from
> http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0208
> .mspx (Hey Scripting Guy) that performs one search and replace in one text
> file:
>
> *******Begin example*********
>
> Const ForReading = 1
> Const ForWriting = 2
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)
>
> strText = objFile.ReadAll
> objFile.Close
> strNewText = Replace(strText, "Jim ", "James ")
>
> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
> objFile.WriteLine strNewText
> objFile.Close
>
> *******End example*********
>
> This works fine for my purposes, however I need the script to perform 15
> search and replace operations on the file.
>
> Can I accomplish this just by repeating the following line with different
> values?::
>
> strNewText = Replace(strText, "Jim ", "James ")
Yes. You can have as many Replace statements as desired.

>
> Or is there something else I need to do to have multiple replace
> operations
> performed?
>
> Thanks for any advice you can provide.
>
> FA
>
>
If you have 15 files, you will need to open and close each separately. This
can happen in one script. To happen automatically you will need to schedule
the script in Task Scheduler. The script must run with credentials that have
write permissions on the files.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
 

My Computer

P

Pegasus \(MVP\)

#3
"FenderAxe" <[email protected]> wrote in message
news:[email protected]

> Hi there --
>
> I've never created a script before now, and what I want to do is
> periodically have a script go into fifteen text files and do multiple
> search and replaces in each file. Ideally this would happen automatically,
> such as one time per day.
>
> I tested the example code from
> http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0208
> .mspx (Hey Scripting Guy) that performs one search and replace in one text
> file:
>
> *******Begin example*********
>
> Const ForReading = 1
> Const ForWriting = 2
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)
>
> strText = objFile.ReadAll
> objFile.Close
> strNewText = Replace(strText, "Jim ", "James ")
>
> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
> objFile.WriteLine strNewText
> objFile.Close
>
> *******End example*********
>
> This works fine for my purposes, however I need the script to perform 15
> search and replace operations on the file.
>
> Can I accomplish this just by repeating the following line with different
> values?::
>
> strNewText = Replace(strText, "Jim ", "James ")
>
> Or is there something else I need to do to have multiple replace
> operations
> performed?
>
> Thanks for any advice you can provide.
>
> FA
Welcome back!
You could do it like so:

Const ForReading = 1, ForWriting = 2
Const Start = 1, Count = - 1

arrFrom = Split("Jim Jack John Jill")
arrTo = Split("James Jake Jack Jane")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)

strText = objFile.ReadAll
objFile.Close
For i = 0 To UBound(arrFrom)
strText = Replace(strText, arrFrom(i), arrTo(i), _
Start, Count, vbTextCompare)
Next

Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
objFile.WriteLine strText
objFile.Close
 

My Computer

F

FenderAxe

#4
"Richard Mueller [MVP]" <[email protected]> wrote in
news:[email protected]:

> See comment inline below:
>
> "FenderAxe" <[email protected]> wrote in message
> news:[email protected]

>> Hi there --
>>
>> I've never created a script before now, and what I want to do is
>> periodically have a script go into fifteen text files and do multiple
>> search and replaces in each file. Ideally this would happen
>> automatically, such as one time per day.
>>
>> I tested the example code from
>> http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/he
>> y0208 .mspx (Hey Scripting Guy) that performs one search and replace
>> in one text file:
>>
>> *******Begin example*********
>>
>> Const ForReading = 1
>> Const ForWriting = 2
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)
>>
>> strText = objFile.ReadAll
>> objFile.Close
>> strNewText = Replace(strText, "Jim ", "James ")
>>
>> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
>> objFile.WriteLine strNewText
>> objFile.Close
>>
>> *******End example*********
>>
>> This works fine for my purposes, however I need the script to perform
>> 15 search and replace operations on the file.
>>
>> Can I accomplish this just by repeating the following line with
>> different values?::
>>
>> strNewText = Replace(strText, "Jim ", "James ")
>
> Yes. You can have as many Replace statements as desired.
>

>>
>> Or is there something else I need to do to have multiple replace
>> operations
>> performed?
>>
>> Thanks for any advice you can provide.
>>
>> FA
>>
>>
>
> If you have 15 files, you will need to open and close each separately.
> This can happen in one script. To happen automatically you will need
> to schedule the script in Task Scheduler. The script must run with
> credentials that have write permissions on the files.
>
I gave this a try with the strNewText line modified and then repeated as
follows:


*****Begin script*****

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
ForReading)

strText = objFile.ReadAll
objFile.Close

strNewText = Replace(strText, "J:\Music\Blues", "H:\Media2\Blues")
strNewText = Replace(strText, "J:\Music\Classical", "G:\Media2\Classical")
strNewText = Replace(strText, "J:\Music\Country", "G:\Media2\Country")
strNewText = Replace(strText, "J:\Music\Disco", "G:\Media2\Disco")
strNewText = Replace(strText, "J:\Music\Folk", "G:\Media2\Folk")
strNewText = Replace(strText, "J:\Music\Jazz", "G:\Media2\Jazz")
strNewText = Replace(strText, "J:\Music\Misc", "G:\Media2\Misc")
strNewText = Replace(strText, "J:\Music\Pop", "G:\Media2\Pop")
strNewText = Replace(strText, "J:\Music\R and B", "G:\Media2\R and B")
strNewText = Replace(strText, "J:\Music\Reggae", "G:\Media2\Reggae")
strNewText = Replace(strText, "J:\Music\Rock A-C", "H:\Media\Rock A-C")
strNewText = Replace(strText, "J:\Music\Rock D-G","H:\Media\Rock D-G")
strNewText = Replace(strText, "J:\Music\Rock H-M", "H:\Media\Rock H-M")
strNewText = Replace(strText, "J:\Music\Rock N-P", "H:\Media\Rock N-P")
strNewText = Replace(strText, "J:\Music\Rock Q-S", "H:\Media\Rock Q-S")
strNewText = Replace(strText, "J:\Music\Rock T-Z", "H:\Media\Rock T-Z")
strNewText = Replace(strText, "J:\Music\Soundtrack",
"G:\Media2\Soundtrack")
strNewText = Replace(strText, "J:\Music\Xmas", "G:\Media2\Xmas")
strNewText = Replace(strText, "J:\Music\Zydeco", "G:\Media2\Zydeco")

Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
ForWriting)
objFile.WriteLine strNewText
objFile.Close

*****End script*****

Unfortunately, this didn't work -- the playlist m3u file was not updated,
although I did not receive any error messages at the command prompt.

The command that I ran and results I recieved at the prompt was:

C:\Users\Jrm>cscript I:\Documents\WSH\playlistfix.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Interestingly, the script works when I only have one "strNewText" item in
place.

FA
 

My Computer

T

Todd Vargo

#5
"FenderAxe" <[email protected]> wrote in message
news:[email protected]

> Hi there --
>
> I've never created a script before now, and what I want to do is
> periodically have a script go into fifteen text files and do multiple
> search and replaces in each file. Ideally this would happen automatically,
> such as one time per day.
>
> I tested the example code from
>
http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0208

> .mspx (Hey Scripting Guy) that performs one search and replace in one text
> file:
>
> *******Begin example*********
>
> Const ForReading = 1
> Const ForWriting = 2
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)
>
> strText = objFile.ReadAll
> objFile.Close
> strNewText = Replace(strText, "Jim ", "James ")
>
> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
> objFile.WriteLine strNewText
> objFile.Close
>
> *******End example*********
>
> This works fine for my purposes, however I need the script to perform 15
> search and replace operations on the file.
>
> Can I accomplish this just by repeating the following line with different
> values?::
>
> strNewText = Replace(strText, "Jim ", "James ")
>
> Or is there something else I need to do to have multiple replace
operations

> performed?
>
> Thanks for any advice you can provide.
Since your first replacement is from strText to strNewText, subsequent
replacements can be from strNewText to strNewText. The final result will
have all of the replacements in strNewText prior to writing back to file.

strNewText = Replace(strText, "Jim ", "James ")
strNewText = Replace(strNewText, "Mike ", "Miles ")
strNewText = Replace(strNewText, "Guitar ", "Axe ")

You can load these values into an array as other posters demonstrate. The
same method can be applied to the file names but you can just as easily
provide the filenames to a subroutine.

Update "C:\Scripts\Text.txt"
Update "C:\Other Location\Text1.txt"
Update "C:\Yet Another\Text2.txt"
'and so on...

Sub Update(filename)
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(filename, ForReading)
strText = objFile.ReadAll
objFile.Close

strNewText = Replace(strText, "Jim ", "James ")
strNewText = Replace(strNewText, "Mike ", "Miles ")
strNewText = Replace(strNewText, "FenderGuitar ", "FenderAxe ")
'and so on...

Set objFile = objFSO.OpenTextFile(filename, ForWriting)
objFile.Write strNewText
objFile.Close
End Sub

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
 

My Computer

R

Richard Mueller [MVP]

#6
"FenderAxe" <[email protected]> wrote in message
news:[email protected]

> "Richard Mueller [MVP]" <[email protected]> wrote in
> news:[email protected]:
>

>> See comment inline below:
>>
>> "FenderAxe" <[email protected]> wrote in message
>> news:[email protected]

>>> Hi there --
>>>
>>> I've never created a script before now, and what I want to do is
>>> periodically have a script go into fifteen text files and do multiple
>>> search and replaces in each file. Ideally this would happen
>>> automatically, such as one time per day.
>>>
>>> I tested the example code from
>>> http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/he
>>> y0208 .mspx (Hey Scripting Guy) that performs one search and replace
>>> in one text file:
>>>
>>> *******Begin example*********
>>>
>>> Const ForReading = 1
>>> Const ForWriting = 2
>>>
>>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)
>>>
>>> strText = objFile.ReadAll
>>> objFile.Close
>>> strNewText = Replace(strText, "Jim ", "James ")
>>>
>>> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
>>> objFile.WriteLine strNewText
>>> objFile.Close
>>>
>>> *******End example*********
>>>
>>> This works fine for my purposes, however I need the script to perform
>>> 15 search and replace operations on the file.
>>>
>>> Can I accomplish this just by repeating the following line with
>>> different values?::
>>>
>>> strNewText = Replace(strText, "Jim ", "James ")
>>
>> Yes. You can have as many Replace statements as desired.
>>

>>>
>>> Or is there something else I need to do to have multiple replace
>>> operations
>>> performed?
>>>
>>> Thanks for any advice you can provide.
>>>
>>> FA
>>>
>>>
>>
>> If you have 15 files, you will need to open and close each separately.
>> This can happen in one script. To happen automatically you will need
>> to schedule the script in Task Scheduler. The script must run with
>> credentials that have write permissions on the files.
>>
>
> I gave this a try with the strNewText line modified and then repeated as
> follows:
>
>
> *****Begin script*****
>
> Const ForReading = 1
> Const ForWriting = 2
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
> ForReading)
>
> strText = objFile.ReadAll
> objFile.Close
>
> strNewText = Replace(strText, "J:\Music\Blues", "H:\Media2\Blues")
> strNewText = Replace(strText, "J:\Music\Classical", "G:\Media2\Classical")
> strNewText = Replace(strText, "J:\Music\Country", "G:\Media2\Country")
> strNewText = Replace(strText, "J:\Music\Disco", "G:\Media2\Disco")
> strNewText = Replace(strText, "J:\Music\Folk", "G:\Media2\Folk")
> strNewText = Replace(strText, "J:\Music\Jazz", "G:\Media2\Jazz")
> strNewText = Replace(strText, "J:\Music\Misc", "G:\Media2\Misc")
> strNewText = Replace(strText, "J:\Music\Pop", "G:\Media2\Pop")
> strNewText = Replace(strText, "J:\Music\R and B", "G:\Media2\R and B")
> strNewText = Replace(strText, "J:\Music\Reggae", "G:\Media2\Reggae")
> strNewText = Replace(strText, "J:\Music\Rock A-C", "H:\Media\Rock A-C")
> strNewText = Replace(strText, "J:\Music\Rock D-G","H:\Media\Rock D-G")
> strNewText = Replace(strText, "J:\Music\Rock H-M", "H:\Media\Rock H-M")
> strNewText = Replace(strText, "J:\Music\Rock N-P", "H:\Media\Rock N-P")
> strNewText = Replace(strText, "J:\Music\Rock Q-S", "H:\Media\Rock Q-S")
> strNewText = Replace(strText, "J:\Music\Rock T-Z", "H:\Media\Rock T-Z")
> strNewText = Replace(strText, "J:\Music\Soundtrack",
> "G:\Media2\Soundtrack")
> strNewText = Replace(strText, "J:\Music\Xmas", "G:\Media2\Xmas")
> strNewText = Replace(strText, "J:\Music\Zydeco", "G:\Media2\Zydeco")
>
> Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
> ForWriting)
> objFile.WriteLine strNewText
> objFile.Close
>
> *****End script*****
>
> Unfortunately, this didn't work -- the playlist m3u file was not updated,
> although I did not receive any error messages at the command prompt.
>
> The command that I ran and results I recieved at the prompt was:
>
> C:\Users\Jrm>cscript I:\Documents\WSH\playlistfix.vbs
> Microsoft (R) Windows Script Host Version 5.7
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> Interestingly, the script works when I only have one "strNewText" item in
> place.
>
> FA
You redefine the value of strNewText each time based on the original value
of strText. Previous modified values are lost. So only the last Replace is
used. You should use:
===========
strText = objFile.ReadAll
objFile.Close

strNewText = Replace(strText, "J:\Music\Blues", "H:\Media2\Blues")
strNewText = Replace(strNewText, "J:\Music\Classical",
"G:\Media2\Classical")
strNewText = Replace(strNewText, "J:\Music\Country", "G:\Media2\Country")
strNewText = Replace(strNewText, "J:\Music\Disco", "G:\Media2\Disco")
strNewText = Replace(strNewText, "J:\Music\Folk", "G:\Media2\Folk")
strNewText = Replace(strNewText, "J:\Music\Jazz", "G:\Media2\Jazz")
strNewText = Replace(strNewText, "J:\Music\Misc", "G:\Media2\Misc")
strNewText = Replace(strNewText, "J:\Music\Pop", "G:\Media2\Pop")
strNewText = Replace(strNewText, "J:\Music\R and B", "G:\Media2\R and B")
strNewText = Replace(strNewText, "J:\Music\Reggae", "G:\Media2\Reggae")
strNewText = Replace(strNewText, "J:\Music\Rock A-C", "H:\Media\Rock A-C")
strNewText = Replace(strNewText, "J:\Music\Rock D-G","H:\Media\Rock D-G")
strNewText = Replace(strNewText, "J:\Music\Rock H-M", "H:\Media\Rock H-M")
strNewText = Replace(strNewText, "J:\Music\Rock N-P", "H:\Media\Rock N-P")
strNewText = Replace(strNewText, "J:\Music\Rock Q-S", "H:\Media\Rock Q-S")
strNewText = Replace(strNewText, "J:\Music\Rock T-Z", "H:\Media\Rock T-Z")
strNewText = Replace(strNewText, "J:\Music\Soundtrack",
"G:\Media2\Soundtrack")
strNewText = Replace(strNewText, "J:\Music\Xmas", "G:\Media2\Xmas")
strNewText = Replace(strNewText, "J:\Music\Zydeco", "G:\Media2\Zydeco")

Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
ForWriting)
objFile.WriteLine strNewText
objFile.Close
========
Now the modifications are cumulative. Does this make sense?

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
 

My Computer

F

FenderAxe

#7
"Richard Mueller [MVP]" <[email protected]> wrote in
news:#[email protected]:

>
> "FenderAxe" <[email protected]> wrote in message
> news:[email protected]

>> "Richard Mueller [MVP]" <[email protected]> wrote
>> in news:[email protected]:
>>

>>> See comment inline below:
>>>
>>> "FenderAxe" <[email protected]> wrote in message
>>> news:[email protected]
>>>> Hi there --
>>>>
>>>> I've never created a script before now, and what I want to do is
>>>> periodically have a script go into fifteen text files and do
>>>> multiple search and replaces in each file. Ideally this would
>>>> happen automatically, such as one time per day.
>>>>
>>>> I tested the example code from
>>>> http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/
>>>> he y0208 .mspx (Hey Scripting Guy) that performs one search and
>>>> replace in one text file:
>>>>
>>>> *******Begin example*********
>>>>
>>>> Const ForReading = 1
>>>> Const ForWriting = 2
>>>>
>>>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>>> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt",
>>>> ForReading)
>>>>
>>>> strText = objFile.ReadAll
>>>> objFile.Close
>>>> strNewText = Replace(strText, "Jim ", "James ")
>>>>
>>>> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt",
>>>> ForWriting) objFile.WriteLine strNewText
>>>> objFile.Close
>>>>
>>>> *******End example*********
>>>>
>>>> This works fine for my purposes, however I need the script to
>>>> perform 15 search and replace operations on the file.
>>>>
>>>> Can I accomplish this just by repeating the following line with
>>>> different values?::
>>>>
>>>> strNewText = Replace(strText, "Jim ", "James ")
>>>
>>> Yes. You can have as many Replace statements as desired.
>>>
>>>>
>>>> Or is there something else I need to do to have multiple replace
>>>> operations
>>>> performed?
>>>>
>>>> Thanks for any advice you can provide.
>>>>
>>>> FA
>>>>
>>>>
>>>
>>> If you have 15 files, you will need to open and close each
>>> separately. This can happen in one script. To happen automatically
>>> you will need to schedule the script in Task Scheduler. The script
>>> must run with credentials that have write permissions on the files.
>>>
>>
>> I gave this a try with the strNewText line modified and then
>> repeated as follows:
>>
>>
>> *****Begin script*****
>>
>> Const ForReading = 1
>> Const ForWriting = 2
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and
>> Faves.m3u", ForReading)
>>
>> strText = objFile.ReadAll
>> objFile.Close
>>
>> strNewText = Replace(strText, "J:\Music\Blues", "H:\Media2\Blues")
>> strNewText = Replace(strText, "J:\Music\Classical",
>> "G:\Media2\Classical") strNewText = Replace(strText,
>> "J:\Music\Country", "G:\Media2\Country") strNewText =
>> Replace(strText, "J:\Music\Disco", "G:\Media2\Disco") strNewText =
>> Replace(strText, "J:\Music\Folk", "G:\Media2\Folk") strNewText =
>> Replace(strText, "J:\Music\Jazz", "G:\Media2\Jazz") strNewText =
>> Replace(strText, "J:\Music\Misc", "G:\Media2\Misc") strNewText =
>> Replace(strText, "J:\Music\Pop", "G:\Media2\Pop") strNewText =
>> Replace(strText, "J:\Music\R and B", "G:\Media2\R and B") strNewText
>> = Replace(strText, "J:\Music\Reggae", "G:\Media2\Reggae") strNewText
>> = Replace(strText, "J:\Music\Rock A-C", "H:\Media\Rock A-C")
>> strNewText = Replace(strText, "J:\Music\Rock D-G","H:\Media\Rock
>> D-G") strNewText = Replace(strText, "J:\Music\Rock H-M",
>> "H:\Media\Rock H-M") strNewText = Replace(strText, "J:\Music\Rock
>> N-P", "H:\Media\Rock N-P") strNewText = Replace(strText,
>> "J:\Music\Rock Q-S", "H:\Media\Rock Q-S") strNewText =
>> Replace(strText, "J:\Music\Rock T-Z", "H:\Media\Rock T-Z") strNewText
>> = Replace(strText, "J:\Music\Soundtrack", "G:\Media2\Soundtrack")
>> strNewText = Replace(strText, "J:\Music\Xmas", "G:\Media2\Xmas")
>> strNewText = Replace(strText, "J:\Music\Zydeco", "G:\Media2\Zydeco")
>>
>> Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and
>> Faves.m3u", ForWriting)
>> objFile.WriteLine strNewText
>> objFile.Close
>>
>> *****End script*****
>>
>> Unfortunately, this didn't work -- the playlist m3u file was not
>> updated, although I did not receive any error messages at the command
>> prompt.
>>
>> The command that I ran and results I recieved at the prompt was:
>>
>> C:\Users\Jrm>cscript I:\Documents\WSH\playlistfix.vbs
>> Microsoft (R) Windows Script Host Version 5.7
>> Copyright (C) Microsoft Corporation. All rights reserved.
>>
>> Interestingly, the script works when I only have one "strNewText"
>> item in place.
>>
>> FA
>
> You redefine the value of strNewText each time based on the original
> value of strText. Previous modified values are lost. So only the last
> Replace is used. You should use:
> ===========
> strText = objFile.ReadAll
> objFile.Close
>
> strNewText = Replace(strText, "J:\Music\Blues", "H:\Media2\Blues")
> strNewText = Replace(strNewText, "J:\Music\Classical",
> "G:\Media2\Classical")
> strNewText = Replace(strNewText, "J:\Music\Country",
> "G:\Media2\Country") strNewText = Replace(strNewText,
> "J:\Music\Disco", "G:\Media2\Disco") strNewText = Replace(strNewText,
> "J:\Music\Folk", "G:\Media2\Folk") strNewText = Replace(strNewText,
> "J:\Music\Jazz", "G:\Media2\Jazz") strNewText = Replace(strNewText,
> "J:\Music\Misc", "G:\Media2\Misc") strNewText = Replace(strNewText,
> "J:\Music\Pop", "G:\Media2\Pop") strNewText = Replace(strNewText,
> "J:\Music\R and B", "G:\Media2\R and B") strNewText =
> Replace(strNewText, "J:\Music\Reggae", "G:\Media2\Reggae") strNewText
> = Replace(strNewText, "J:\Music\Rock A-C", "H:\Media\Rock A-C")
> strNewText = Replace(strNewText, "J:\Music\Rock D-G","H:\Media\Rock
> D-G") strNewText = Replace(strNewText, "J:\Music\Rock H-M",
> "H:\Media\Rock H-M") strNewText = Replace(strNewText, "J:\Music\Rock
> N-P", "H:\Media\Rock N-P") strNewText = Replace(strNewText,
> "J:\Music\Rock Q-S", "H:\Media\Rock Q-S") strNewText =
> Replace(strNewText, "J:\Music\Rock T-Z", "H:\Media\Rock T-Z")
> strNewText = Replace(strNewText, "J:\Music\Soundtrack",
> "G:\Media2\Soundtrack") strNewText = Replace(strNewText,
> "J:\Music\Xmas", "G:\Media2\Xmas") strNewText = Replace(strNewText,
> "J:\Music\Zydeco", "G:\Media2\Zydeco")
>
> Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
> ForWriting)
> objFile.WriteLine strNewText
> objFile.Close
> ========
> Now the modifications are cumulative. Does this make sense?
>
To be honest, it only partly makes sense -- I guess you're creating a new
variable somehow and replacing the value with a new value?

With the script modified this way it worked though. :-) Thanks for your
help with this.

FA
 

My Computer

F

FenderAxe

#8
"Todd Vargo" <[email protected]> wrote in
news:[email protected]:

>
> "FenderAxe" <[email protected]> wrote in message
> news:[email protected]

>> Hi there --
>>
>> I've never created a script before now, and what I want to do is
>> periodically have a script go into fifteen text files and do multiple
>> search and replaces in each file. Ideally this would happen
>> automatically, such as one time per day.
>>
>> I tested the example code from
>>
> http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey
> 0208

>> .mspx (Hey Scripting Guy) that performs one search and replace in one
>> text file:
>>
>> *******Begin example*********
>>
>> Const ForReading = 1
>> Const ForWriting = 2
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)
>>
>> strText = objFile.ReadAll
>> objFile.Close
>> strNewText = Replace(strText, "Jim ", "James ")
>>
>> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
>> objFile.WriteLine strNewText
>> objFile.Close
>>
>> *******End example*********
>>
>> This works fine for my purposes, however I need the script to perform
>> 15 search and replace operations on the file.
>>
>> Can I accomplish this just by repeating the following line with
>> different values?::
>>
>> strNewText = Replace(strText, "Jim ", "James ")
>>
>> Or is there something else I need to do to have multiple replace
> operations

>> performed?
>>
>> Thanks for any advice you can provide.
>
> Since your first replacement is from strText to strNewText, subsequent
> replacements can be from strNewText to strNewText. The final result
> will have all of the replacements in strNewText prior to writing back
> to file.
>
> strNewText = Replace(strText, "Jim ", "James ")
> strNewText = Replace(strNewText, "Mike ", "Miles ")
> strNewText = Replace(strNewText, "Guitar ", "Axe ")
>
> You can load these values into an array as other posters demonstrate.
> The same method can be applied to the file names but you can just as
> easily provide the filenames to a subroutine.
>
> Update "C:\Scripts\Text.txt"
> Update "C:\Other Location\Text1.txt"
> Update "C:\Yet Another\Text2.txt"
> 'and so on...
>
> Sub Update(filename)
> Const ForReading = 1
> Const ForWriting = 2
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> Set objFile = objFSO.OpenTextFile(filename, ForReading)
> strText = objFile.ReadAll
> objFile.Close
>
> strNewText = Replace(strText, "Jim ", "James ")
> strNewText = Replace(strNewText, "Mike ", "Miles ")
> strNewText = Replace(strNewText, "FenderGuitar ", "FenderAxe ")
> 'and so on...
>
> Set objFile = objFSO.OpenTextFile(filename, ForWriting)
> objFile.Write strNewText
> objFile.Close
> End Sub
>
Hi Todd --

I tried this with the list of files at the top:

Update "C:\Scripts\Text.txt"
Update "C:\Other Location\Text1.txt"
Update "C:\Yet Another\Text2.txt"
'and so on...

: But when I ran the script I received an error that stated "Disk not
ready." This didn't really make sense because the disk was powered up and
running fine. So I'm not sure what the problem is -- but I appreciate your
suggestion anyhow, because I'm learning more with each post you folks
provide, and I appreciate that a lot.

FA
 

My Computer

T

Todd Vargo

#9
FenderAxe wrote:

> Todd Vargo wrote:

> > FenderAxe wrote:

> >> Thanks for any advice you can provide.
> >
> > Since your first replacement is from strText to strNewText, subsequent
> > replacements can be from strNewText to strNewText. The final result
> > will have all of the replacements in strNewText prior to writing back
> > to file.
> >
> > strNewText = Replace(strText, "Jim ", "James ")
> > strNewText = Replace(strNewText, "Mike ", "Miles ")
> > strNewText = Replace(strNewText, "Guitar ", "Axe ")
> >
> > You can load these values into an array as other posters demonstrate.
> > The same method can be applied to the file names but you can just as
> > easily provide the filenames to a subroutine.
> >
> > Update "C:\Scripts\Text.txt"
> > Update "C:\Other Location\Text1.txt"
> > Update "C:\Yet Another\Text2.txt"
> > 'and so on...
> >
> > Sub Update(filename)
> > Const ForReading = 1
> > Const ForWriting = 2
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> >
> > Set objFile = objFSO.OpenTextFile(filename, ForReading)
> > strText = objFile.ReadAll
> > objFile.Close
> >
> > strNewText = Replace(strText, "Jim ", "James ")
> > strNewText = Replace(strNewText, "Mike ", "Miles ")
> > strNewText = Replace(strNewText, "FenderGuitar ", "FenderAxe ")
> > 'and so on...
> >
> > Set objFile = objFSO.OpenTextFile(filename, ForWriting)
> > objFile.Write strNewText
> > objFile.Close
> > End Sub
> >
>
> Hi Todd --
>
> I tried this with the list of files at the top:
>
> Update "C:\Scripts\Text.txt"
> Update "C:\Other Location\Text1.txt"
> Update "C:\Yet Another\Text2.txt"
> 'and so on...
>
> : But when I ran the script I received an error that stated "Disk not
> ready." This didn't really make sense because the disk was powered up and
> running fine. So I'm not sure what the problem is -- but I appreciate your
> suggestion anyhow, because I'm learning more with each post you folks
> provide, and I appreciate that a lot.
Why would you try it using my example file specs? You should replace with
your real file specs which you want to modify. Since the "Disk not ready"
message does not make sense, and having read your other post, I suspect you
tried putting the strings to be replaced (which are file paths in the other
post) where the specs to files to be modified should go.

For further help, please copy/paste the exact code that returns the "Disk
not ready" message so we can examine it.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
 

My Computer

T

Todd Vargo

#10
FenderAxe wrote:

> "Richard Mueller [MVP]" wrote:

> > You redefine the value of strNewText each time based on the original
> > value of strText. Previous modified values are lost. So only the last
> > Replace is used. You should use:
> > ===========
> > strText = objFile.ReadAll
> > objFile.Close
> >
> > strNewText = Replace(strText, "J:\Music\Blues", "H:\Media2\Blues")
> > strNewText = Replace(strNewText, "J:\Music\Classical",
> > "G:\Media2\Classical")
> > strNewText = Replace(strNewText, "J:\Music\Country",
> > "G:\Media2\Country") strNewText = Replace(strNewText,
> > "J:\Music\Disco", "G:\Media2\Disco") strNewText = Replace(strNewText,
> > "J:\Music\Folk", "G:\Media2\Folk") strNewText = Replace(strNewText,
> > "J:\Music\Jazz", "G:\Media2\Jazz") strNewText = Replace(strNewText,
> > "J:\Music\Misc", "G:\Media2\Misc") strNewText = Replace(strNewText,
> > "J:\Music\Pop", "G:\Media2\Pop") strNewText = Replace(strNewText,
> > "J:\Music\R and B", "G:\Media2\R and B") strNewText =
> > Replace(strNewText, "J:\Music\Reggae", "G:\Media2\Reggae") strNewText
> > = Replace(strNewText, "J:\Music\Rock A-C", "H:\Media\Rock A-C")
> > strNewText = Replace(strNewText, "J:\Music\Rock D-G","H:\Media\Rock
> > D-G") strNewText = Replace(strNewText, "J:\Music\Rock H-M",
> > "H:\Media\Rock H-M") strNewText = Replace(strNewText, "J:\Music\Rock
> > N-P", "H:\Media\Rock N-P") strNewText = Replace(strNewText,
> > "J:\Music\Rock Q-S", "H:\Media\Rock Q-S") strNewText =
> > Replace(strNewText, "J:\Music\Rock T-Z", "H:\Media\Rock T-Z")
> > strNewText = Replace(strNewText, "J:\Music\Soundtrack",
> > "G:\Media2\Soundtrack") strNewText = Replace(strNewText,
> > "J:\Music\Xmas", "G:\Media2\Xmas") strNewText = Replace(strNewText,
> > "J:\Music\Zydeco", "G:\Media2\Zydeco")
> >
> > Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
> > ForWriting)
> > objFile.WriteLine strNewText
> > objFile.Close
> > ========
> > Now the modifications are cumulative. Does this make sense?
> >
>
> To be honest, it only partly makes sense -- I guess you're creating a new
> variable somehow and replacing the value with a new value?
No. His code (like mine) reuses the strNewText variable on the second and
latter Replace() statements.

>
> With the script modified this way it worked though. :-) Thanks for your
> help with this.
Richard might have also mentioned, you could replace all those Replace()
lines with just these two lines (in this order).

strNewText = Replace(strText, "J:\Music\Rock", "H:\Media\Rock)
strNewText = Replace(strNewText, "J:\Music", "G:\Media2")

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
 

My Computer

A

Al Dunbar

#11
"Todd Vargo" <[email protected]> wrote in message
news:[email protected]

> FenderAxe wrote:

>> "Richard Mueller [MVP]" wrote:

>> > You redefine the value of strNewText each time based on the original
>> > value of strText. Previous modified values are lost. So only the last
>> > Replace is used. You should use:
>> > ===========
>> > strText = objFile.ReadAll
>> > objFile.Close
>> >
>> > strNewText = Replace(strText, "J:\Music\Blues", "H:\Media2\Blues")
>> > strNewText = Replace(strNewText, "J:\Music\Classical",
>> > "G:\Media2\Classical")
>> > strNewText = Replace(strNewText, "J:\Music\Country",
>> > "G:\Media2\Country") strNewText = Replace(strNewText,
>> > "J:\Music\Disco", "G:\Media2\Disco") strNewText = Replace(strNewText,
>> > "J:\Music\Folk", "G:\Media2\Folk") strNewText = Replace(strNewText,
>> > "J:\Music\Jazz", "G:\Media2\Jazz") strNewText = Replace(strNewText,
>> > "J:\Music\Misc", "G:\Media2\Misc") strNewText = Replace(strNewText,
>> > "J:\Music\Pop", "G:\Media2\Pop") strNewText = Replace(strNewText,
>> > "J:\Music\R and B", "G:\Media2\R and B") strNewText =
>> > Replace(strNewText, "J:\Music\Reggae", "G:\Media2\Reggae") strNewText
>> > = Replace(strNewText, "J:\Music\Rock A-C", "H:\Media\Rock A-C")
>> > strNewText = Replace(strNewText, "J:\Music\Rock D-G","H:\Media\Rock
>> > D-G") strNewText = Replace(strNewText, "J:\Music\Rock H-M",
>> > "H:\Media\Rock H-M") strNewText = Replace(strNewText, "J:\Music\Rock
>> > N-P", "H:\Media\Rock N-P") strNewText = Replace(strNewText,
>> > "J:\Music\Rock Q-S", "H:\Media\Rock Q-S") strNewText =
>> > Replace(strNewText, "J:\Music\Rock T-Z", "H:\Media\Rock T-Z")
>> > strNewText = Replace(strNewText, "J:\Music\Soundtrack",
>> > "G:\Media2\Soundtrack") strNewText = Replace(strNewText,
>> > "J:\Music\Xmas", "G:\Media2\Xmas") strNewText = Replace(strNewText,
>> > "J:\Music\Zydeco", "G:\Media2\Zydeco")
>> >
>> > Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
>> > ForWriting)
>> > objFile.WriteLine strNewText
>> > objFile.Close
>> > ========
>> > Now the modifications are cumulative. Does this make sense?
>> >
>>
>> To be honest, it only partly makes sense -- I guess you're creating a new
>> variable somehow and replacing the value with a new value?
>
> No. His code (like mine) reuses the strNewText variable on the second and
> latter Replace() statements.
>

>>
>> With the script modified this way it worked though. :-) Thanks for your
>> help with this.
>
> Richard might have also mentioned, you could replace all those Replace()
> lines with just these two lines (in this order).
>
> strNewText = Replace(strText, "J:\Music\Rock", "H:\Media\Rock)
> strNewText = Replace(strNewText, "J:\Music", "G:\Media2")
.... always assuming that *every* folder within "J:\music" has its
corresponding folder in "G:\Media2".

/Al
 

My Computer

F

FenderAxe

#12
"Todd Vargo" <[email protected]> wrote in
news:#[email protected]:

> FenderAxe wrote:

>> Todd Vargo wrote:

>> > FenderAxe wrote:
>> >> Thanks for any advice you can provide.
>> >
>> > Since your first replacement is from strText to strNewText,
>> > subsequent replacements can be from strNewText to strNewText. The
>> > final result will have all of the replacements in strNewText prior
>> > to writing back to file.
>> >
>> > strNewText = Replace(strText, "Jim ", "James ")
>> > strNewText = Replace(strNewText, "Mike ", "Miles ")
>> > strNewText = Replace(strNewText, "Guitar ", "Axe ")
>> >
>> > You can load these values into an array as other posters
>> > demonstrate. The same method can be applied to the file names but
>> > you can just as easily provide the filenames to a subroutine.
>> >
>> > Update "C:\Scripts\Text.txt"
>> > Update "C:\Other Location\Text1.txt"
>> > Update "C:\Yet Another\Text2.txt"
>> > 'and so on...
>> >
>> > Sub Update(filename)
>> > Const ForReading = 1
>> > Const ForWriting = 2
>> > Set objFSO = CreateObject("Scripting.FileSystemObject")
>> >
>> > Set objFile = objFSO.OpenTextFile(filename, ForReading)
>> > strText = objFile.ReadAll
>> > objFile.Close
>> >
>> > strNewText = Replace(strText, "Jim ", "James ")
>> > strNewText = Replace(strNewText, "Mike ", "Miles ")
>> > strNewText = Replace(strNewText, "FenderGuitar ", "FenderAxe ")
>> > 'and so on...
>> >
>> > Set objFile = objFSO.OpenTextFile(filename, ForWriting)
>> > objFile.Write strNewText
>> > objFile.Close
>> > End Sub
>> >
>>
>> Hi Todd --
>>
>> I tried this with the list of files at the top:
>>
>> Update "C:\Scripts\Text.txt"
>> Update "C:\Other Location\Text1.txt"
>> Update "C:\Yet Another\Text2.txt"
>> 'and so on...
>>
>> : But when I ran the script I received an error that stated "Disk not
>> ready." This didn't really make sense because the disk was powered up
>> and running fine. So I'm not sure what the problem is -- but I
>> appreciate your suggestion anyhow, because I'm learning more with
>> each post you folks provide, and I appreciate that a lot.
>
> Why would you try it using my example file specs? You should replace
> with your real file specs which you want to modify. Since the "Disk
> not ready" message does not make sense, and having read your other
> post, I suspect you tried putting the strings to be replaced (which
> are file paths in the other post) where the specs to files to be
> modified should go.
>
> For further help, please copy/paste the exact code that returns the
> "Disk not ready" message so we can examine it.
>
I didn't try it using example specs, I replaced the values with the actual
names of my files. I was just indicating that I had added the "Update
'filename'" section and that because of this the script no longer works.

Here is the code I've run and received the disk not ready error:

Update "F:\Documents\Playlists Source\1968 Top 100.m3u"
Update "F:\Documents\Playlists Source\1972 Top 100.m3u"
Update "F:\Documents\Playlists Source\1973 Top 100.m3u"
Update "F:\Documents\Playlists Source\1974 Top 100.m3u"
Update "F:\Documents\Playlists Source\1975 Top 100.m3u"
Update "F:\Documents\Playlists Source\1979 Top 100.m3u"
Update "F:\Documents\Playlists Source\AM Radio.m3u"
Update "F:\Documents\Playlists Source\Amarcord Nino Rota.m3u"
Update "F:\Documents\Playlists Source\Audiophile.m3u"
Update "F:\Documents\Playlists Source\Blues.m3u"
Update "F:\Documents\Playlists Source\Bs and Faves.m3u"
Update "F:\Documents\Playlists Source\B's and Faves 2.m3u"
Update "F:\Documents\Playlists Source\Christmas (short).m3u"
Update "F:\Documents\Playlists Source\Clapton and Rock.m3u"
Update "F:\Documents\Playlists Source\Cocktails 1.m3u"
Update "F:\Documents\Playlists Source\Cocktails 2.m3u"
Update "F:\Documents\Playlists Source\College.m3u"
Update "F:\Documents\Playlists Source\Country.m3u"
Update "F:\Documents\Playlists Source\Dr Winston O Boogie.m3u"
Update "F:\Documents\Playlists Source\Dylan.m3u"
Update "F:\Documents\Playlists Source\Eagles.m3u"
Update "F:\Documents\Playlists Source\ELO and Friends.m3u"
Update "F:\Documents\Playlists Source\Elvis Costello.m3u"
Update "F:\Documents\Playlists Source\Guitar Blues.m3u"
Update "F:\Documents\Playlists Source\Hard Rock 1.m3u"
Update "F:\Documents\Playlists Source\Hard Rock 2.m3u"
Update "F:\Documents\Playlists Source\Hendrix.m3u"
Update "F:\Documents\Playlists Source\Hippy Hippy Shake.m3u"
Update "F:\Documents\Playlists Source\Jacky Jack.m3u"
Update "F:\Documents\Playlists Source\James Taylor.m3u"
Update "F:\Documents\Playlists Source\Jazz - Cool.m3u"
Update "F:\Documents\Playlists Source\Jazz - Misc.m3u"
Update "F:\Documents\Playlists Source\Jazz - New.m3u"
Update "F:\Documents\Playlists Source\Jazz - Smooth.m3u"
Update "F:\Documents\Playlists Source\Jazz Rock.m3u"
Update "F:\Documents\Playlists Source\Jazz- Slow.m3u"
Update "F:\Documents\Playlists Source\JJ and Eric.m3u"
Update "F:\Documents\Playlists Source\Joni Mitchell.m3u"
Update "F:\Documents\Playlists Source\Kinks.m3u"
Update "F:\Documents\Playlists Source\LA.m3u"
Update "F:\Documents\Playlists Source\Led Zep.m3u"
Update "F:\Documents\Playlists Source\Lexus.m3u"
Update "F:\Documents\Playlists Source\Loggins and Messina.m3u"
Update "F:\Documents\Playlists Source\Maximum 1970's R&B.m3u"
Update "F:\Documents\Playlists Source\New Orleans.m3u"
Update "F:\Documents\Playlists Source\Playlist Playlist.m3u"
Update "F:\Documents\Playlists Source\Pop.m3u"
Update "F:\Documents\Playlists Source\R and B 1.m3u"
Update "F:\Documents\Playlists Source\R and B 2.m3u"
Update "F:\Documents\Playlists Source\RCA Victor Jazz.m3u"
Update "F:\Documents\Playlists Source\Ricky Nelson.m3u"
Update "F:\Documents\Playlists Source\Sinatra.m3u"
Update "F:\Documents\Playlists Source\Smallville.m3u"
Update "F:\Documents\Playlists Source\Soft Rock 1.m3u"
Update "F:\Documents\Playlists Source\Soft Rock 2.m3u"
Update "F:\Documents\Playlists Source\Soul 2007.m3u"
Update "F:\Documents\Playlists Source\Southbound.m3u"
Update "F:\Documents\Playlists Source\Speed 50s.m3u"
Update "F:\Documents\Playlists Source\Steely Dan.m3u"
Update "F:\Documents\Playlists Source\Traffic.m3u"
Update "F:\Documents\Playlists Source\Ultimate Who.m3u"
Update "F:\Documents\Playlists Source\VanMo.m3u"
Update "F:\Documents\Playlists Source\Walsh.m3u"
Update "F:\Documents\Playlists Source\Wonder.m3u"

Sub Update(filename)

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
ForReading)

strText = objFile.ReadAll
objFile.Close

strNewText = Replace(strText, "J:\Music\Blues", "H:\Media2\Blues")
strNewText = Replace(strNewText, "J:\Music\Classical",
"G:\Media2\Classical")
strNewText = Replace(strNewText, "J:\Music\Country", "G:\Media2\Country")
strNewText = Replace(strNewText, "J:\Music\Disco", "G:\Media2\Disco")
strNewText = Replace(strNewText, "J:\Music\Folk", "G:\Media2\Folk")
strNewText = Replace(strNewText, "J:\Music\Jazz", "G:\Media2\Jazz")
strNewText = Replace(strNewText, "J:\Music\Misc", "G:\Media2\Misc")
strNewText = Replace(strNewText, "J:\Music\Pop", "G:\Media2\Pop")
strNewText = Replace(strNewText, "J:\Music\R and B", "G:\Media2\R and B")
strNewText = Replace(strNewText, "J:\Music\Reggae", "G:\Media2\Reggae")
strNewText = Replace(strNewText, "J:\Music\Rock A-C", "H:\Media\Rock A-C")
strNewText = Replace(strNewText, "J:\Music\Rock D-G","H:\Media\Rock D-G")
strNewText = Replace(strNewText, "J:\Music\Rock H-M", "H:\Media\Rock H-M")
strNewText = Replace(strNewText, "J:\Music\Rock N-P", "H:\Media\Rock N-P")
strNewText = Replace(strNewText, "J:\Music\Rock Q-S", "H:\Media\Rock Q-S")
strNewText = Replace(strNewText, "J:\Music\Rock T-Z", "H:\Media\Rock T-Z")
strNewText = Replace(strNewText, "J:\Music\Soundtrack",
"G:\Media2\Soundtrack")
strNewText = Replace(strNewText, "J:\Music\Xmas", "G:\Media2\Xmas")
strNewText = Replace(strNewText, "J:\Music\Zydeco", "G:\Media2\Zydeco")

Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
ForWriting)
objFile.WriteLine strNewText
objFile.Close

End Sub
 

My Computer

T

Todd Vargo

#13
FenderAxe wrote:

> Todd Vargo wrote:

> > For further help, please copy/paste the exact code that returns the
> > "Disk not ready" message so we can examine it.
> >
>
> I didn't try it using example specs, I replaced the values with the actual
> names of my files. I was just indicating that I had added the "Update
> 'filename'" section and that because of this the script no longer works.
>
> Here is the code I've run and received the disk not ready error:
You did not indicate which line reports the error therefore I have to guess
below.


>
> Update "F:\Documents\Playlists Source\1968 Top 100.m3u"
> Update "F:\Documents\Playlists Source\1972 Top 100.m3u"
> Update "F:\Documents\Playlists Source\1973 Top 100.m3u"
....

>
> Sub Update(filename)
>
> Const ForReading = 1
> Const ForWriting = 2
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
> ForReading)
Line above is hard coded to drive I:. It should be the variable named
'filename' as originally posted. Since drive F: is not being accessed, it
must be drive I: that was not ready either here or below. In effect, you are
bypassing the long list of files which you intended to have updated above.


>
> strText = objFile.ReadAll
> objFile.Close
>
> strNewText = Replace(strText, "J:\Music\Blues", "H:\Media2\Blues")
....

>
> Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
> ForWriting)
Same issue with drive I: here. What type of drive is I:? It must be able to
be written to (on the fly) otherwise that could be what is giving the drive
not ready message even with media in the drive.



> objFile.WriteLine strNewText
> objFile.Close
>
> End Sub

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
 

My Computer

T

Todd Vargo

#14
Todd Vargo wrote:

> FenderAxe wrote:

> > Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and Faves.m3u",
> > ForWriting)
>
> Same issue with drive I: here. What type of drive is I:? It must be able
to

> be written to (on the fly) otherwise that could be what is giving the
drive

> not ready message even with media in the drive.
I just checked it with a CD in the drive. I get "permission denied".

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
 

My Computer

F

FenderAxe

#15
FenderAxe <[email protected]> wrote in
news:[email protected]:

> "Todd Vargo" <[email protected]> wrote in
> news:[email protected]:
>

>> Todd Vargo wrote:

>>> FenderAxe wrote:
>>> > Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and
>>> > Faves.m3u", ForWriting)
>>>
>>> Same issue with drive I: here. What type of drive is I:? It must be
>>> able
>> to

>>> be written to (on the fly) otherwise that could be what is giving
>>> the
>> drive

>>> not ready message even with media in the drive.
>>
>> I just checked it with a CD in the drive. I get "permission denied".
>>
>
> Hi Todd --
>
> Thanks for all of your comments. The reason drive I is mentioned is
> because I was testing the short version of the script on a computer
> other than the one it is eventually going to run on, but for this last
> test I moved the script to the correct computer, but didn't change
> that part of the script to use the variable "filename." The computer
> the script is running on doesn't have a drive I, which explains the
> error.
>
> I will modify those two lines as follows:
>
> Set objFile = objFSO.OpenTextFile(filename, ForReading)
>
> Set objFile = objFSO.OpenTextFile(filename, ForWriting)
>
> And try running the script again.
>
> Thanks again for your assistance with this.
>
> FA
>
OK, I just ran a test of the script a couple of times, once by typing the
execution command at a prompt and one time by having the execution command
run from a batch file -- and it worked great both times.

I'm just thrilled, and I can't tell you how much I appreciate your help.
This is going to save me hundreds of hours. Thank you so much.

Now I'm going to be on the lookout for more things I can write scripts for.
<g>

Also, just so you know, while I can't assist anyone (yet) with scripting, I
have areas of expertise and I assist people in newsgroups on a weekly, and
sometimes daily, basis.

Thanks again everyone --

FA
 

My Computer

A

Al Dunbar

#16
"FenderAxe" <[email protected]> wrote in message
news:[email protected]

> FenderAxe <[email protected]> wrote in
> news:[email protected]:
>

>> "Todd Vargo" <[email protected]> wrote in
>> news:[email protected]:
>>

>>> Todd Vargo wrote:
>>>> FenderAxe wrote:
>>>> > Set objFile = objFSO.OpenTextFile("I:\Documents\WSH\Bs and
>>>> > Faves.m3u", ForWriting)
>>>>
>>>> Same issue with drive I: here. What type of drive is I:? It must be
>>>> able
>>> to
>>>> be written to (on the fly) otherwise that could be what is giving
>>>> the
>>> drive
>>>> not ready message even with media in the drive.
>>>
>>> I just checked it with a CD in the drive. I get "permission denied".
>>>
>>
>> Hi Todd --
>>
>> Thanks for all of your comments. The reason drive I is mentioned is
>> because I was testing the short version of the script on a computer
>> other than the one it is eventually going to run on, but for this last
>> test I moved the script to the correct computer, but didn't change
>> that part of the script to use the variable "filename." The computer
>> the script is running on doesn't have a drive I, which explains the
>> error.
>>
>> I will modify those two lines as follows:
>>
>> Set objFile = objFSO.OpenTextFile(filename, ForReading)
>>
>> Set objFile = objFSO.OpenTextFile(filename, ForWriting)
>>
>> And try running the script again.
>>
>> Thanks again for your assistance with this.
>>
>> FA
>>
>
> OK, I just ran a test of the script a couple of times, once by typing the
> execution command at a prompt and one time by having the execution command
> run from a batch file -- and it worked great both times.
>
> I'm just thrilled, and I can't tell you how much I appreciate your help.
> This is going to save me hundreds of hours. Thank you so much.
>
> Now I'm going to be on the lookout for more things I can write scripts
> for.
> <g>
LOL. You can write scripts for anything, so I'd stick with the ones that
will give the best return. Maybe you will be able to save a few hundred more
hours...

> Also, just so you know, while I can't assist anyone (yet) with scripting,
> I
> have areas of expertise and I assist people in newsgroups on a weekly, and
> sometimes daily, basis.
That's what it's all about. And it probably won't be long before you will be
assisting with scripting. I felt the same way when I started.

/Al
 

My Computer