Hey first post here, also new to scripting.

I'm trying to create a script that reads a text file taking the path
from that file and then copying the file from the path in the text
file to a specific destination.

I've got the reading of the text file down and everything seems to be
ok, except when it goes to copy the file, when it tries to copy the
file I get a Permission Denied message, this is a local copy from root
of C to a temp folder and I'm admin on the machine so I can't
understand why it would be a permission issue.

Here is the script:

Const ForReading = 1
Dim SourceServer

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\test.txt", ForReading)

strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , ",")
Wscript.Echo "Server name: " & arrServiceList(0)
set SourceServer = objFSO.GetFile(arrServiceList(0))
Wscript.Echo "Copy " & SourceServer
SourceServer.Copy("C:\temp\test")

Any suggestions are much apprciated.

Re: Error 800A0046 when trying to copy file locally by ekkehard

ekkehard
Thu Feb 28 12:54:19 CST 2008

Adam Becker schrieb:
> Hey first post here, also new to scripting.
>
> I'm trying to create a script that reads a text file taking the path
> from that file and then copying the file from the path in the text
> file to a specific destination.
>
> I've got the reading of the text file down and everything seems to be
> ok, except when it goes to copy the file, when it tries to copy the
> file I get a Permission Denied message, this is a local copy from root
> of C to a temp folder and I'm admin on the machine so I can't
> understand why it would be a permission issue.
>
> Here is the script:
>
> Const ForReading = 1
> Dim SourceServer
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile _
> ("c:\test.txt", ForReading)
>
> strNextLine = objTextFile.Readline

Not tested, but:
objTextFile.Close

> arrServiceList = Split(strNextLine , ",")
> Wscript.Echo "Server name: " & arrServiceList(0)
> set SourceServer = objFSO.GetFile(arrServiceList(0))
> Wscript.Echo "Copy " & SourceServer
> SourceServer.Copy("C:\temp\test")
>
> Any suggestions are much apprciated.

Re: Error 800A0046 when trying to copy file locally by Adam

Adam
Thu Feb 28 13:35:35 CST 2008

Thanks for the suggestion, I modifed the script to include the
objTextfile.Close:

Const ForReading =3D 1
Dim SourceServer

Set objFSO =3D CreateObject("Scripting.FileSystemObject")
Set objTextFile =3D objFSO.OpenTextFile("c:\test.txt", ForReading)

strNextLine =3D objTextFile.Readline
arrServiceList =3D Split(strNextLine , ",")
objTextFile.Close
Wscript.Echo "Server name: " & arrServiceList(0)
set SourceServer =3D objFSO.GetFile(arrServiceList(0))
Wscript.Echo "Copy " & SourceServer
SourceServer.Copy("C:\temp\test")



Still getting the same error.

On Feb 28, 1:54=A0pm, "ekkehard.horner" <ekkehard.hor...@arcor.de>
wrote:
>
> Not tested, but:
> =A0 =A0 =A0 =A0objTextFile.Close
>
>
>
> > =A0 =A0 arrServiceList =3D Split(strNextLine , ",")
> > =A0 =A0 Wscript.Echo "Server name: " & arrServiceList(0)
> > =A0 =A0 set SourceServer =3D objFSO.GetFile(arrServiceList(0))
> > =A0 =A0 Wscript.Echo "Copy " & SourceServer
> > =A0 =A0 SourceServer.Copy("C:\temp\test")
>
> > Any suggestions are much apprciated.- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


Re: Error 800A0046 when trying to copy file locally by Corey

Corey
Thu Feb 28 13:56:48 CST 2008

Assuming c:\test.txt has something like this on one line:

\\server\share,\\server2\share,c:\temp

Try this:

'=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Const ForReading =3D 1
Dim SourceServer


Set objFSO =3D CreateObject("Scripting.FileSystemObject")
Set objTextFile =3D objFSO.OpenTextFile("c:\test.txt", ForReading)


strNextLine =3D objTextFile.Readline
arrServiceList =3D Split(strNextLine , ",")
objTextFile.Close
Wscript.Echo "Copying to: " & arrServiceList(0)
Set objTextFile =3D objFSO.GetFile("c:\test.txt")
objTextFile.Copy( arrServiceList(0) )

'=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D





On Feb 28, 2:35=A0pm, Adam Becker <vengeance...@hotmail.com> wrote:
> Thanks for the suggestion, I modifed the script to include the
> objTextfile.Close:
>
> Const ForReading =3D 1
> Dim SourceServer
>
> Set objFSO =3D CreateObject("Scripting.FileSystemObject")
> Set objTextFile =3D objFSO.OpenTextFile("c:\test.txt", ForReading)
>
> =A0 =A0 strNextLine =3D objTextFile.Readline
> =A0 =A0 arrServiceList =3D Split(strNextLine , ",")
> =A0 =A0 objTextFile.Close
> =A0 =A0 Wscript.Echo "Server name: " & arrServiceList(0)
> =A0 =A0 set SourceServer =3D objFSO.GetFile(arrServiceList(0))
> =A0 =A0 Wscript.Echo "Copy " & SourceServer
> =A0 =A0 SourceServer.Copy("C:\temp\test")
>
> Still getting the same error.
>
> On Feb 28, 1:54=A0pm, "ekkehard.horner" <ekkehard.hor...@arcor.de>
> wrote:
>
>
>
>
>
> > Not tested, but:
> > =A0 =A0 =A0 =A0objTextFile.Close
>
> > > =A0 =A0 arrServiceList =3D Split(strNextLine , ",")
> > > =A0 =A0 Wscript.Echo "Server name: " & arrServiceList(0)
> > > =A0 =A0 set SourceServer =3D objFSO.GetFile(arrServiceList(0))
> > > =A0 =A0 Wscript.Echo "Copy " & SourceServer
> > > =A0 =A0 SourceServer.Copy("C:\temp\test")
>
> > > Any suggestions are much apprciated.- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


Re: Error 800A0046 when trying to copy file locally by Tom

Tom
Thu Feb 28 14:00:45 CST 2008

On Feb 28, 2:35 pm, Adam Becker <vengeance...@hotmail.com> wrote:
> Thanks for the suggestion, I modifed the script to include the
> objTextfile.Close:
>
> Const ForReading = 1
> Dim SourceServer
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile("c:\test.txt", ForReading)
>
> strNextLine = objTextFile.Readline
> arrServiceList = Split(strNextLine , ",")
> objTextFile.Close
> Wscript.Echo "Server name: " & arrServiceList(0)
> set SourceServer = objFSO.GetFile(arrServiceList(0))
> Wscript.Echo "Copy " & SourceServer
> SourceServer.Copy("C:\temp\test")
>
> Still getting the same error.
>
> On Feb 28, 1:54 pm, "ekkehard.horner" <ekkehard.hor...@arcor.de>
> wrote:
>
>
>
> > Not tested, but:
> > objTextFile.Close
>
> > > arrServiceList = Split(strNextLine , ",")
> > > Wscript.Echo "Server name: " & arrServiceList(0)
> > > set SourceServer = objFSO.GetFile(arrServiceList(0))
> > > Wscript.Echo "Copy " & SourceServer
> > > SourceServer.Copy("C:\temp\test")
>
> > > Any suggestions are much apprciated.- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -

Try ...

objTextFile.Close
set objTextFile = Nothing ' probably not important
Wscript.Echo "Server name: " & arrServiceList(0)
set SourceServer = objFSO.GetFile(arrServiceList(0))
Wscript.Echo "Copy " & SourceServer
' But I think the Overwrite argument for the Copy is the real cause
bOverwrite = TRUE
SourceServer.Copy "C:\temp\test", bOverwrite

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: Error 800A0046 when trying to copy file locally by Adam

Adam
Thu Feb 28 14:33:52 CST 2008

In the txt file it only has one line right now for testing and that
is:

C:\sdat5048.exe

Now the weird thing is your script worekd but because you used:

objTextFile.Copy( arrServiceList(0) )

it was copying to the same source. The items I'm going to have listed
in the array are going to be the source and I want to copy them to a
specific destination. As soon as I changed the:

objTextFile.Copy( arrServiceList(0) )

to another destination so:

objTextFile.Copy( "C:\temp\test" )

I run into the Permission denied.

On Feb 28, 2:56=A0pm, Corey Thomas <coreytho...@gmail.com> wrote:
> Assuming c:\test.txt has something like this on one line:
>
> \\server\share,\\server2\share,c:\temp
>
> Try this:
>
> '=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> Const ForReading =3D 1
> Dim SourceServer
>
> Set objFSO =3D CreateObject("Scripting.FileSystemObject")
> Set objTextFile =3D objFSO.OpenTextFile("c:\test.txt", ForReading)
>
> =A0 =A0 strNextLine =3D objTextFile.Readline
> =A0 =A0 arrServiceList =3D Split(strNextLine , ",")
> =A0 =A0 objTextFile.Close
> =A0 =A0 Wscript.Echo "Copying to: " & arrServiceList(0)
> =A0 =A0 Set objTextFile =3D objFSO.GetFile("c:\test.txt")
> =A0 =A0 objTextFile.Copy( arrServiceList(0) )
>
> '=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
>

Re: Error 800A0046 when trying to copy file locally by Adam

Adam
Thu Feb 28 14:36:24 CST 2008

Ok I tried this:

Const ForReading =3D 1
Dim SourceServer

Set objFSO =3D CreateObject("Scripting.FileSystemObject")
Set objTextFile =3D objFSO.OpenTextFile("c:\test.txt", ForReading)

strNextLine =3D objTextFile.Readline
arrServiceList =3D Split(strNextLine , ",")
objTextFile.Close
set objTextFile =3D Nothing
Wscript.Echo "Server name: " & arrServiceList(0)
set SourceServer =3D objFSO.GetFile(arrServiceList(0))
Wscript.Echo "Copy " & SourceServer
bOverwrite =3D TRUE
SourceServer.Copy"C:\temp\test",bOverwrite

same error, I can understand why it's not allowing my to do a simple
copy.

On Feb 28, 3:00=A0pm, Tom Lavedas <tglba...@cox.net> wrote:
>
> Try ...
>
> =A0 =A0 objTextFile.Close
> =A0 =A0 set objTextFile =3D Nothing ' probably not important
> =A0 =A0 Wscript.Echo "Server name: " & arrServiceList(0)
> =A0 =A0 set SourceServer =3D objFSO.GetFile(arrServiceList(0))
> =A0 =A0 Wscript.Echo "Copy " & SourceServer
> ' But I think the Overwrite argument for the Copy is the real cause
> =A0 =A0 bOverwrite =3D TRUE
> =A0 =A0 SourceServer.Copy "C:\temp\test", bOverwrite
>
> Tom Lavedas
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3Dhttp://members.cox.net/tglbatch/wsh/- Hid=
e quoted text -
>
> - Show quoted text -


Re: Error 800A0046 when trying to copy file locally by Adam

Adam
Thu Feb 28 14:43:27 CST 2008

Figured it out, it was the:

SourceServer.Copy"C:\temp\test",bOverwrite

It had to be:

SourceServer.Copy"C:\temp\test\",bOverwrite

It needed that last \ as soon as I added that it worked :/

Re: Error 800A0046 when trying to copy file locally by Corey

Corey
Thu Feb 28 14:47:30 CST 2008

Congrats! I figured it was something simple. Sorry for sending you
around. I wasn't sure what you had in that text file. :)

-Corey

On Feb 28, 3:43=A0pm, Adam Becker <vengeance...@hotmail.com> wrote:
> Figured it out, it was the:
>
> SourceServer.Copy"C:\temp\test",bOverwrite
>
> It had to be:
>
> SourceServer.Copy"C:\temp\test\",bOverwrite
>
> It needed that last \ as soon as I added that it worked :/


Re: Error 800A0046 when trying to copy file locally by Adam

Adam
Thu Feb 28 14:56:00 CST 2008

Yea thanks everyone for the help, this is why I never became a
programmer back silly things like one little \

But thanks again.

On Feb 28, 3:47=A0pm, Corey Thomas <coreytho...@gmail.com> wrote:
> Congrats! =A0 I figured it was something simple. =A0Sorry for sending you
> around. =A0I wasn't sure what you had in that text file. =A0:)
>
> -Corey
>
> On Feb 28, 3:43=A0pm, Adam Becker <vengeance...@hotmail.com> wrote:
>
>
>
> > Figured it out, it was the:
>
> > SourceServer.Copy"C:\temp\test",bOverwrite
>
> > It had to be:
>
> > SourceServer.Copy"C:\temp\test\",bOverwrite
>
> > It needed that last \ as soon as I added that it worked :/- Hide quoted =
text -
>
> - Show quoted text -