I need to copy and overwrite a number of files programmatically and I'd like
to know how to modify the following code from technet to use an array of
"copy from" names.

'starting point
Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\FSO\ScriptLog.txt" , "D:\Archive\", OverwriteExisting

'end starting point

'start pseudo code
dim ary(3)

ary(1) = "C:\FSO\ScriptLog1.txt"
ary(2) = "C:\FSO\ScriptLog2.txt"
ary(3) = "C:\FSO\ScriptLog3.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
For i = 1 to 3
' something on the lines of:
objFSO.CopyFile "" & ary(3) &"" , "D:\Archive\", OverwriteExisting
Next

'end pseudo code

Any help will be greatly appreciated.

Thanks,
Raul

RE: script that uses an array copy an array of file names by raul

raul
Thu Jan 25 21:11:02 CST 2007

The Subject text doesn't make sense. I have reposted this question.

"Raul" wrote:

> I need to copy and overwrite a number of files programmatically and I'd like
> to know how to modify the following code from technet to use an array of
> "copy from" names.
>
> 'starting point
> Const OverwriteExisting = TRUE
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> objFSO.CopyFile "C:\FSO\ScriptLog.txt" , "D:\Archive\", OverwriteExisting
>
> 'end starting point
>
> 'start pseudo code
> dim ary(3)
>
> ary(1) = "C:\FSO\ScriptLog1.txt"
> ary(2) = "C:\FSO\ScriptLog2.txt"
> ary(3) = "C:\FSO\ScriptLog3.txt"
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> For i = 1 to 3
> ' something on the lines of:
> objFSO.CopyFile "" & ary(3) &"" , "D:\Archive\", OverwriteExisting
> Next
>
> 'end pseudo code
>
> Any help will be greatly appreciated.
>
> Thanks,
> Raul
>
>
>
>

Re: script that uses an array copy an array of file names by joseomjr

joseomjr
Thu Jan 25 21:15:58 CST 2007

Dim arr1(2)

arr1(0) = "C:\FSO\ScriptLog1.txt"
arr1(1) = "C:\FSO\ScriptLog2.txt"
arr1(2) = "C:\FSO\ScriptLog3.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
For i = 0 to 2
' something on the lines of:
objFSO.CopyFile arr1(i), "D:\Archive\", OverwriteExisting
' WScript.Echo arr1(i), "D:\Archive\", OverwriteExisting
Next

On Jan 25, 7:04 pm, Raul <r...@nothere.com> wrote:
> I need to copy and overwrite a number of files programmatically and I'd like
> to know how to modify the following code from technet to use an array of
> "copy from" names.
>
> 'starting point
> Const OverwriteExisting = TRUE
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> objFSO.CopyFile "C:\FSO\ScriptLog.txt" , "D:\Archive\", OverwriteExisting
>
> 'end starting point
>
> 'start pseudo code
> dim ary(3)
>
> ary(1) = "C:\FSO\ScriptLog1.txt"
> ary(2) = "C:\FSO\ScriptLog2.txt"
> ary(3) = "C:\FSO\ScriptLog3.txt"
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> For i = 1 to 3
> ' something on the lines of:
> objFSO.CopyFile "" & ary(3) &"" , "D:\Archive\", OverwriteExisting
> Next
>
> 'end pseudo code
>
> Any help will be greatly appreciated.
>
> Thanks,
> Raul


Re: script that uses an array copy an array of file names by raul

raul
Thu Jan 25 21:57:01 CST 2007

I'm getting a VBScript runtime error (permission denied).

The actual path and names are longer and do contain spaces. Also I'm Using
an underscore for a line continuation symbol.

Thanks,
Raul



"joseomjr@gmail.com" wrote:

> Dim arr1(2)
>
> arr1(0) = "C:\FSO\ScriptLog1.txt"
> arr1(1) = "C:\FSO\ScriptLog2.txt"
> arr1(2) = "C:\FSO\ScriptLog3.txt"
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> For i = 0 to 2
> ' something on the lines of:
> objFSO.CopyFile arr1(i), "D:\Archive\", OverwriteExisting
> ' WScript.Echo arr1(i), "D:\Archive\", OverwriteExisting
> Next
>
> On Jan 25, 7:04 pm, Raul <r...@nothere.com> wrote:
> > I need to copy and overwrite a number of files programmatically and I'd like
> > to know how to modify the following code from technet to use an array of
> > "copy from" names.
> >
> > 'starting point
> > Const OverwriteExisting = TRUE
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > objFSO.CopyFile "C:\FSO\ScriptLog.txt" , "D:\Archive\", OverwriteExisting
> >
> > 'end starting point
> >
> > 'start pseudo code
> > dim ary(3)
> >
> > ary(1) = "C:\FSO\ScriptLog1.txt"
> > ary(2) = "C:\FSO\ScriptLog2.txt"
> > ary(3) = "C:\FSO\ScriptLog3.txt"
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > For i = 1 to 3
> > ' something on the lines of:
> > objFSO.CopyFile "" & ary(3) &"" , "D:\Archive\", OverwriteExisting
> > Next
> >
> > 'end pseudo code
> >
> > Any help will be greatly appreciated.
> >
> > Thanks,
> > Raul
>
>

Re: script that uses an array copy an array of file names by joseomjr

joseomjr
Thu Jan 25 22:20:24 CST 2007

Try this.
objFSO.CopyFile Chr(34) & arr1(i) & Chr(34), "D:\Archive\",
OverwriteExisting

On Jan 25, 7:57 pm, Raul <r...@nothere.com> wrote:
> I'm getting a VBScript runtime error (permission denied).
>
> The actual path and names are longer and do contain spaces. Also I'm Using
> an underscore for a line continuation symbol.
>
> Thanks,
> Raul
>
> "joseo...@gmail.com" wrote:
> > Dim arr1(2)
>
> > arr1(0) = "C:\FSO\ScriptLog1.txt"
> > arr1(1) = "C:\FSO\ScriptLog2.txt"
> > arr1(2) = "C:\FSO\ScriptLog3.txt"
>
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > For i = 0 to 2
> > ' something on the lines of:
> > objFSO.CopyFile arr1(i), "D:\Archive\", OverwriteExisting
> > ' WScript.Echo arr1(i), "D:\Archive\", OverwriteExisting
> > Next
>
> > On Jan 25, 7:04 pm, Raul <r...@nothere.com> wrote:
> > > I need to copy and overwrite a number of files programmatically and I'd like
> > > to know how to modify the following code from technet to use an array of
> > > "copy from" names.
>
> > > 'starting point
> > > Const OverwriteExisting = TRUE
>
> > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > objFSO.CopyFile "C:\FSO\ScriptLog.txt" , "D:\Archive\", OverwriteExisting
>
> > > 'end starting point
>
> > > 'start pseudo code
> > > dim ary(3)
>
> > > ary(1) = "C:\FSO\ScriptLog1.txt"
> > > ary(2) = "C:\FSO\ScriptLog2.txt"
> > > ary(3) = "C:\FSO\ScriptLog3.txt"
>
> > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > For i = 1 to 3
> > > ' something on the lines of:
> > > objFSO.CopyFile "" & ary(3) &"" , "D:\Archive\", OverwriteExisting
> > > Next
>
> > > 'end pseudo code
>
> > > Any help will be greatly appreciated.
>
> > > Thanks,
> > > Raul


Re: script that uses an array copy an array of file names by raul

raul
Thu Jan 25 22:47:00 CST 2007

Adding the chr(34) results in a "bad file name or number error".

I think the syntax in your original post was correct. I'm wondering if I
have a security setting that is creating the "permission denied" error.

By the way, I tried:

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\FSO\ScriptLog1.txt" , "D:\Archive\", OverwriteExisting

and also got the same "permission denied" error.

Thanks,
Raul

"joseomjr@gmail.com" wrote:

> Try this.
> objFSO.CopyFile Chr(34) & arr1(i) & Chr(34), "D:\Archive\",
> OverwriteExisting
>
> On Jan 25, 7:57 pm, Raul <r...@nothere.com> wrote:
> > I'm getting a VBScript runtime error (permission denied).
> >
> > The actual path and names are longer and do contain spaces. Also I'm Using
> > an underscore for a line continuation symbol.
> >
> > Thanks,
> > Raul
> >
> > "joseo...@gmail.com" wrote:
> > > Dim arr1(2)
> >
> > > arr1(0) = "C:\FSO\ScriptLog1.txt"
> > > arr1(1) = "C:\FSO\ScriptLog2.txt"
> > > arr1(2) = "C:\FSO\ScriptLog3.txt"
> >
> > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > For i = 0 to 2
> > > ' something on the lines of:
> > > objFSO.CopyFile arr1(i), "D:\Archive\", OverwriteExisting
> > > ' WScript.Echo arr1(i), "D:\Archive\", OverwriteExisting
> > > Next
> >
> > > On Jan 25, 7:04 pm, Raul <r...@nothere.com> wrote:
> > > > I need to copy and overwrite a number of files programmatically and I'd like
> > > > to know how to modify the following code from technet to use an array of
> > > > "copy from" names.
> >
> > > > 'starting point
> > > > Const OverwriteExisting = TRUE
> >
> > > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > > objFSO.CopyFile "C:\FSO\ScriptLog.txt" , "D:\Archive\", OverwriteExisting
> >
> > > > 'end starting point
> >
> > > > 'start pseudo code
> > > > dim ary(3)
> >
> > > > ary(1) = "C:\FSO\ScriptLog1.txt"
> > > > ary(2) = "C:\FSO\ScriptLog2.txt"
> > > > ary(3) = "C:\FSO\ScriptLog3.txt"
> >
> > > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > > For i = 1 to 3
> > > > ' something on the lines of:
> > > > objFSO.CopyFile "" & ary(3) &"" , "D:\Archive\", OverwriteExisting
> > > > Next
> >
> > > > 'end pseudo code
> >
> > > > Any help will be greatly appreciated.
> >
> > > > Thanks,
> > > > Raul
>
>

Re: script that uses an array copy an array of file names by Al

Al
Thu Jan 25 22:49:53 CST 2007


<joseomjr@gmail.com> wrote in message
news:1169781358.127314.139380@k78g2000cwa.googlegroups.com...

Or this variant:

> REM Dim arr1(2)

dim arr1


> REM arr1(0) = "C:\FSO\ScriptLog1.txt"
> REM arr1(1) = "C:\FSO\ScriptLog2.txt"
> REM arr1(2) = "C:\FSO\ScriptLog3.txt"


arr1 array( _
"C:\FSO\ScriptLog1.txt", _
"C:\FSO\ScriptLog2.txt", _
"C:\FSO\ScriptLog3.txt" _
)

> Set objFSO = CreateObject("Scripting.FileSystemObject")
> For i = 0 to 2
> ' something on the lines of:
> objFSO.CopyFile arr1(i), "D:\Archive\", OverwriteExisting
> ' WScript.Echo arr1(i), "D:\Archive\", OverwriteExisting
> Next
>
> On Jan 25, 7:04 pm, Raul <r...@nothere.com> wrote:
> > I need to copy and overwrite a number of files programmatically and I'd
like
> > to know how to modify the following code from technet to use an array of
> > "copy from" names.
> >
> > 'starting point
> > Const OverwriteExisting = TRUE
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > objFSO.CopyFile "C:\FSO\ScriptLog.txt" , "D:\Archive\",
OverwriteExisting
> >
> > 'end starting point
> >
> > 'start pseudo code
> > dim ary(3)
> >
> > ary(1) = "C:\FSO\ScriptLog1.txt"
> > ary(2) = "C:\FSO\ScriptLog2.txt"
> > ary(3) = "C:\FSO\ScriptLog3.txt"
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > For i = 1 to 3
> > ' something on the lines of:
> > objFSO.CopyFile "" & ary(3) &"" , "D:\Archive\", OverwriteExisting
> > Next
> >
> > 'end pseudo code
> >
> > Any help will be greatly appreciated.
> >
> > Thanks,
> > Raul
>



Re: script that uses an array copy an array of file names by raul

raul
Thu Jan 25 23:00:00 CST 2007

The syntax in your original post was fine. I had a typo in my copy to folder.

Thank you very much!
Raul

"joseomjr@gmail.com" wrote:

> Try this.
> objFSO.CopyFile Chr(34) & arr1(i) & Chr(34), "D:\Archive\",
> OverwriteExisting
>
> On Jan 25, 7:57 pm, Raul <r...@nothere.com> wrote:
> > I'm getting a VBScript runtime error (permission denied).
> >
> > The actual path and names are longer and do contain spaces. Also I'm Using
> > an underscore for a line continuation symbol.
> >
> > Thanks,
> > Raul
> >
> > "joseo...@gmail.com" wrote:
> > > Dim arr1(2)
> >
> > > arr1(0) = "C:\FSO\ScriptLog1.txt"
> > > arr1(1) = "C:\FSO\ScriptLog2.txt"
> > > arr1(2) = "C:\FSO\ScriptLog3.txt"
> >
> > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > For i = 0 to 2
> > > ' something on the lines of:
> > > objFSO.CopyFile arr1(i), "D:\Archive\", OverwriteExisting
> > > ' WScript.Echo arr1(i), "D:\Archive\", OverwriteExisting
> > > Next
> >
> > > On Jan 25, 7:04 pm, Raul <r...@nothere.com> wrote:
> > > > I need to copy and overwrite a number of files programmatically and I'd like
> > > > to know how to modify the following code from technet to use an array of
> > > > "copy from" names.
> >
> > > > 'starting point
> > > > Const OverwriteExisting = TRUE
> >
> > > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > > objFSO.CopyFile "C:\FSO\ScriptLog.txt" , "D:\Archive\", OverwriteExisting
> >
> > > > 'end starting point
> >
> > > > 'start pseudo code
> > > > dim ary(3)
> >
> > > > ary(1) = "C:\FSO\ScriptLog1.txt"
> > > > ary(2) = "C:\FSO\ScriptLog2.txt"
> > > > ary(3) = "C:\FSO\ScriptLog3.txt"
> >
> > > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > > For i = 1 to 3
> > > > ' something on the lines of:
> > > > objFSO.CopyFile "" & ary(3) &"" , "D:\Archive\", OverwriteExisting
> > > > Next
> >
> > > > 'end pseudo code
> >
> > > > Any help will be greatly appreciated.
> >
> > > > Thanks,
> > > > Raul
>
>

Re: script that uses an array copy an array of file names by raul

raul
Thu Jan 25 23:07:01 CST 2007

Thanks Al, joseomjr's response resolved the issue but I'll try your
suggestion as well.

Thanks again,
Raul


"Al Dunbar [MS-MVP]" wrote:

>
> <joseomjr@gmail.com> wrote in message
> news:1169781358.127314.139380@k78g2000cwa.googlegroups.com...
>
> Or this variant:
>
> > REM Dim arr1(2)
>
> dim arr1
>
>
> > REM arr1(0) = "C:\FSO\ScriptLog1.txt"
> > REM arr1(1) = "C:\FSO\ScriptLog2.txt"
> > REM arr1(2) = "C:\FSO\ScriptLog3.txt"
>
>
> arr1 array( _
> "C:\FSO\ScriptLog1.txt", _
> "C:\FSO\ScriptLog2.txt", _
> "C:\FSO\ScriptLog3.txt" _
> )
>
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > For i = 0 to 2
> > ' something on the lines of:
> > objFSO.CopyFile arr1(i), "D:\Archive\", OverwriteExisting
> > ' WScript.Echo arr1(i), "D:\Archive\", OverwriteExisting
> > Next
> >
> > On Jan 25, 7:04 pm, Raul <r...@nothere.com> wrote:
> > > I need to copy and overwrite a number of files programmatically and I'd
> like
> > > to know how to modify the following code from technet to use an array of
> > > "copy from" names.
> > >
> > > 'starting point
> > > Const OverwriteExisting = TRUE
> > >
> > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > objFSO.CopyFile "C:\FSO\ScriptLog.txt" , "D:\Archive\",
> OverwriteExisting
> > >
> > > 'end starting point
> > >
> > > 'start pseudo code
> > > dim ary(3)
> > >
> > > ary(1) = "C:\FSO\ScriptLog1.txt"
> > > ary(2) = "C:\FSO\ScriptLog2.txt"
> > > ary(3) = "C:\FSO\ScriptLog3.txt"
> > >
> > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > For i = 1 to 3
> > > ' something on the lines of:
> > > objFSO.CopyFile "" & ary(3) &"" , "D:\Archive\", OverwriteExisting
> > > Next
> > >
> > > 'end pseudo code
> > >
> > > Any help will be greatly appreciated.
> > >
> > > Thanks,
> > > Raul
> >
>
>
>

Re: script that uses an array copy an array of file names by Al

Al
Fri Jan 26 10:49:54 CST 2007

You're welcome. It doesn't solve the problem you had, I just find it a
little simpler, especially when you find yourself needing to add or remove
entries.

/Al

"Raul" <raul@nothere.com> wrote in message
news:88867D01-370B-4426-8FBA-861032ACCF7D@microsoft.com...
> Thanks Al, joseomjr's response resolved the issue but I'll try your
> suggestion as well.
>
> Thanks again,
> Raul
>
>
> "Al Dunbar [MS-MVP]" wrote:
>
> >
> > <joseomjr@gmail.com> wrote in message
> > news:1169781358.127314.139380@k78g2000cwa.googlegroups.com...
> >
> > Or this variant:
> >
> > > REM Dim arr1(2)
> >
> > dim arr1
> >
> >
> > > REM arr1(0) = "C:\FSO\ScriptLog1.txt"
> > > REM arr1(1) = "C:\FSO\ScriptLog2.txt"
> > > REM arr1(2) = "C:\FSO\ScriptLog3.txt"
> >
> >
> > arr1 array( _
> > "C:\FSO\ScriptLog1.txt", _
> > "C:\FSO\ScriptLog2.txt", _
> > "C:\FSO\ScriptLog3.txt" _
> > )
> >
> > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > For i = 0 to 2
> > > ' something on the lines of:
> > > objFSO.CopyFile arr1(i), "D:\Archive\", OverwriteExisting
> > > ' WScript.Echo arr1(i), "D:\Archive\", OverwriteExisting
> > > Next
> > >
> > > On Jan 25, 7:04 pm, Raul <r...@nothere.com> wrote:
> > > > I need to copy and overwrite a number of files programmatically and
I'd
> > like
> > > > to know how to modify the following code from technet to use an
array of
> > > > "copy from" names.
> > > >
> > > > 'starting point
> > > > Const OverwriteExisting = TRUE
> > > >
> > > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > > objFSO.CopyFile "C:\FSO\ScriptLog.txt" , "D:\Archive\",
> > OverwriteExisting
> > > >
> > > > 'end starting point
> > > >
> > > > 'start pseudo code
> > > > dim ary(3)
> > > >
> > > > ary(1) = "C:\FSO\ScriptLog1.txt"
> > > > ary(2) = "C:\FSO\ScriptLog2.txt"
> > > > ary(3) = "C:\FSO\ScriptLog3.txt"
> > > >
> > > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > > For i = 1 to 3
> > > > ' something on the lines of:
> > > > objFSO.CopyFile "" & ary(3) &"" , "D:\Archive\", OverwriteExisting
> > > > Next
> > > >
> > > > 'end pseudo code
> > > >
> > > > Any help will be greatly appreciated.
> > > >
> > > > Thanks,
> > > > Raul
> > >
> >
> >
> >