help with a file array problem 
Author Message
 help with a file array problem

using the following VBS (thanks Tom) to do a simple
search and replace with one file...

File = "D:\FILE1.TXT"
const ForReading = 1, ForWriting = 2
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oInFile = oFS.openTextFile(File, ForReading, True)
sText = oInFile.ReadAll
oInFile.Close

Set oOutFile = oFS.openTextFile(File, ForWriting, True)
oOutFile.Write replace(sText, "2000 ", "00 ")
oOutFile.Close

i am trying to put the steps that it executes inside
of an array, so that it will handle:  file1.txt, file2.txt,
and file3.txt...

however, i have not been successful in getting it to work.

i have looked at Clarence's site and two others and cannot
find anything on multiple file arrays.

the syntax i'm using is something like

dim file, files
dim file1, file2, file3

file1 = "D:\file1.txt"
file2 = "D:\file2.txt"
file3 = "D:\file3.txt"

for each file in files
<search and replace code>
next file

i've obviously reached a point where something i don't know
or realise is holding me back.

can anyone pls help?

many thanks...

Hank

* Sent from RemarQ http://www.*-*-*.com/ The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Sat, 21 Sep 2002 03:00:00 GMT  
 help with a file array problem
dim file, files

files = array("D:\file1.txt", _
                 "D:\file2.txt", _
                 "D:\file3.txt")

for each file in files
<search and replace code>
next file

--
Michael Harris
MVP Scripting


using the following VBS (thanks Tom) to do a simple
search and replace with one file...

File = "D:\FILE1.TXT"
const ForReading = 1, ForWriting = 2
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oInFile = oFS.openTextFile(File, ForReading, True)
sText = oInFile.ReadAll
oInFile.Close

Set oOutFile = oFS.openTextFile(File, ForWriting, True)
oOutFile.Write replace(sText, "2000 ", "00 ")
oOutFile.Close

i am trying to put the steps that it executes inside
of an array, so that it will handle:  file1.txt, file2.txt,
and file3.txt...

however, i have not been successful in getting it to work.

i have looked at Clarence's site and two others and cannot
find anything on multiple file arrays.

the syntax i'm using is something like

dim file, files
dim file1, file2, file3

file1 = "D:\file1.txt"
file2 = "D:\file2.txt"
file3 = "D:\file3.txt"

for each file in files
<search and replace code>
next file

i've obviously reached a point where something i don't know
or realise is holding me back.

can anyone pls help?

many thanks...

Hank

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Sat, 21 Sep 2002 03:00:00 GMT  
 help with a file array problem

Quote:

> using the following VBS (thanks Tom) to do a simple
> search and replace with one file...

> File = "D:\FILE1.TXT"
> const ForReading = 1, ForWriting = 2
> Set oFS = CreateObject("Scripting.FileSystemObject")
> Set oInFile = oFS.openTextFile(File, ForReading, True)
> sText = oInFile.ReadAll
> oInFile.Close

> Set oOutFile = oFS.openTextFile(File, ForWriting, True)
> oOutFile.Write replace(sText, "2000 ", "00 ")
> oOutFile.Close

> i am trying to put the steps that it executes inside
> of an array, so that it will handle:  file1.txt, file2.txt,
> and file3.txt...

> however, i have not been successful in getting it to work.

> i have looked at Clarence's site and two others and cannot
> find anything on multiple file arrays.

> the syntax i'm using is something like

> dim file, files
> dim file1, file2, file3

> file1 = "D:\file1.txt"
> file2 = "D:\file2.txt"
> file3 = "D:\file3.txt"

> for each file in files
> <search and replace code>
> next file

> i've obviously reached a point where something i don't know
> or realise is holding me back.

> can anyone pls help?

> many thanks...

> Hank

Yup, you're definitely confused.  The FOR construct you have requires
the 'files' variable in your example to be a 'collection' of files,
which it is not (as written).  And a collection is not an array.
Assuming the file names are just examples of arbitrary names (i.e. that
can't be indexed), you could do something like this ...

files = Array("D:\file1.txt")
files = Array(files, "D:\file2.txt")
files = Array(files, "D:\file3.txt")

Set oFS = CreateObject("Scripting.FileSystemObject")

for i = 0 to UBound(files)
  file = files(i)
  if oFS.FileExists(file) then
    <search and replace code>
  End if
next

If the file names do in fact differ only by the index number, the
following would also work ...

Upper = 3
Set oFS = CreateObject("Scripting.FileSystemObject")

for i = 1 to Upper
  file = "file" & i & ".txt"
  if oFS.FileExists(file) then
    <search and replace code>
  End if
next

If you want to process a number of files in a particular folder, then
you want to create a collection of files to process similar to the
example you posted ...

Set oFS = CreateObject("Scripting.FileSystemObject")
Set files = oFS.GetFolder("C:\Some\Folder).Files

for each file in files
  <search and replace code>
next

The FilesExist() test isn't needed in this case, because only existing
files can be part of the 'files' collection.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/



Sat, 21 Sep 2002 03:00:00 GMT  
 help with a file array problem
dim file, files

files = array("D:\file1.txt", _
                 "D:\file2.txt", _
                 "D:\file3.txt")

for each file in files
<search and replace code>
next

Note the change on "next".  "next file" isn't supported (or necessary).

--
Michael Harris
MVP Scripting


dim file, files

files = array("D:\file1.txt", _
                 "D:\file2.txt", _
                 "D:\file3.txt")

for each file in files
<search and replace code>
next file

--
Michael Harris
MVP Scripting


using the following VBS (thanks Tom) to do a simple
search and replace with one file...

File = "D:\FILE1.TXT"
const ForReading = 1, ForWriting = 2
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oInFile = oFS.openTextFile(File, ForReading, True)
sText = oInFile.ReadAll
oInFile.Close

Set oOutFile = oFS.openTextFile(File, ForWriting, True)
oOutFile.Write replace(sText, "2000 ", "00 ")
oOutFile.Close

i am trying to put the steps that it executes inside
of an array, so that it will handle:  file1.txt, file2.txt,
and file3.txt...

however, i have not been successful in getting it to work.

i have looked at Clarence's site and two others and cannot
find anything on multiple file arrays.

the syntax i'm using is something like

dim file, files
dim file1, file2, file3

file1 = "D:\file1.txt"
file2 = "D:\file2.txt"
file3 = "D:\file3.txt"

for each file in files
<search and replace code>
next file

i've obviously reached a point where something i don't know
or realise is holding me back.

can anyone pls help?

many thanks...

Hank

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Sat, 21 Sep 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Array of Bytes problem! Help

2. Help! Storing Arrays in Session Variables - problem

3. HELP on How to read CSV file content into Array

4. Help converting server-side VBScript array into client-side JScript array

5. Please Help with Excel Files/Arrays

6. wsh/ jscript : BUG : array of array, 2D array

7. HELP!!! LOADPICTURE FILE PATH PROBLEM

8. Help! Problems with EPS files and colorimage

9. Please Help! File Access Component Problem

10. PS file size problem, help needed.

11. Help: problem with inserting a .eps file into tex

12. Problem in using file object, please help

 

 
Powered by phpBB® Forum Software