Pegasus
Thu Jul 03 11:14:17 CDT 2008
"Lord Dark Helmet" <LordDarkHelmet@discussions.microsoft.com> wrote in
message news:83EF02D7-5E87-44A7-9DC6-CA23BFAC5039@microsoft.com...
> "Tom Lavedas" wrote:
>
>> On Jul 2, 3:43 pm, Lord Dark Helmet
>> <LordDarkHel...@discussions.microsoft.com> wrote:
>> > I am attempting to copy some custom Office Templates into user profiles
>> > when
>> > they log on to the computer. I want it to look to see if the files
>> > exist and
>> > if they don't then copy the files from a network share. Here is the
>> > Code I
>> > have come up with.
>> >
>> > path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\Application
>> > Data\Microsoft\Templates\")
>> > dim objFSO
>> > set objFSO=CreateObject("Scripting.FileSystemObject")
>> > If objFSO.FileExists("path") = False Then
>> > objFSO.CopyFile "\\servername\stdapps\custemp\*.docx", path
>> > End If
>> >
>> > I am getting an error file not found on line 5 character 1 code
>> > 800A0035.
>> > I've checked and templates are there. Any ideas?
>> >
>> > Any Help would be greatly appreciated
>>
>> First, take the quotes from around the variable's name in line five.
>> With the quotes, you are passing the literal string, path, to the
>> FileExists method.
>>
>> Once you fix that, a second problem will arise; specifically, you are
>> passing a folder's path to a function that can only test for a file.
>> If you want to test for the presence of the folder, then change the
>> request to FolderExists, instead. However, I don't think that's what
>> you want either, because if it were the absence of the folder you were
>> checking, the next step when it returned False would be to create the
>> folder - which you are not doing.
>>
>> So, which is it? File or folder?
>>
>> If it's the absence of the folder that it to trigger the action, then
>> try this ...
>>
>> path=CreateObject("WScript.Shell")_
>> .ExpandEnvironmentStrings("%UserProfile%") _
>> & "\Application Data\Microsoft\Templates")
>> dim objFSO
>> set objFSO=CreateObject("Scripting.FileSystemObject")
>> If objFSO.FolderExists(path) = False Then
>> objFSO.CreateFolder path
>> objFSO.CopyFile "\\servername\stdapps\custemp\*.docx", path & "\"
>> End If
>>
>> Tom Lavedas
>> ===========
>>
http://members.cox.net/tglbatch/wsh/
>>
>
> OK I have made some adjustments that you have suggested. What I want it
> to
> do is scan this folder and see if three files exhist and if they don't
> copy
> these files into this folder. So I have changed the code to look in this
> location for the time being one of the three files. If it doesn't exhist
> then copy the correct file there. Here is the code I have now.
>
> Option Explicit
> dim path
> path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\Application
> Data\Microsoft\Templates\")
> dim objFSO
> set objFSO=CreateObject("Scripting.FileSystemObject")
> If objFSO.FileExists(path"\envelope.dotx") = False Then
> objFSO.CopyFile "\\servername\stdapps\custemp\envelope.docx", path & "\"
> End If
>
>
> I am now receiving the following error:
> Expected ')'
> Line 6
> char 26
> Code 800A03EE.
>
> Thanks again for all your help.
>
In the line
If objFSO.FileExists(path"\envelope.dotx") = False Then
you're trying to concatenate the variable 'path' with the string
'\envelope.dotx'. This is fine for batch files but not so fine for
VB Scripts. To concatenate strings in VB Scripts, use the &
operator:
If objFSO.FileExists(path & "envelope.dotx") = False Then
Note also that you have one backslash too many. If 'path' ends
on a backslash then you must not start '\envelope.dotx' with
a backslash. The same goes for Line 7.