Hi,

I need to create a script that moves certain files from a folder and places
them in a new directory. I need to use the Like operator because I only know
the start of the file name. I want to move all of the files that start with
Archive in the config folder.

Here is the code, what should i change to get this working

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

'Copy xcacls.vbs to the users C:\windows\system32 directory
strFilePath = "C:\windows\system32\config"
strDestination = "\\resource\Installs\Backup\Event Logs"

fso.movefile(strFilePath & "Like '%Archive%'", strDestination)

Re: Moving Files by Al

Al
Mon Apr 09 16:11:26 CDT 2007


"Paul" <Paul@discussions.microsoft.com> wrote in message
news:61D3044F-9F7B-46B5-8C8C-1AB728729C15@microsoft.com...
> Hi,
>
> I need to create a script that moves certain files from a folder and
> places
> them in a new directory. I need to use the Like operator because I only
> know
> the start of the file name. I want to move all of the files that start
> with
> Archive in the config folder.
>
> Here is the code, what should i change to get this working
>
> Dim fso
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> 'Copy xcacls.vbs to the users C:\windows\system32 directory
> strFilePath = "C:\windows\system32\config"
> strDestination = "\\resource\Installs\Backup\Event Logs"
>
> fso.movefile(strFilePath & "Like '%Archive%'", strDestination)

The .movefile method expects the source argument to be a valid file
specification, optionally with standard filesystem wildcards in the last
item in the path - it does not have any sort of querying capability. Try
this instead:

fso.movefile(strFilePath & "\archive*.*", strDestination)

/Al



Re: Moving Files by Paul

Paul
Tue Apr 10 15:56:09 CDT 2007

I get this error message when trying to use ur code AL

Microsoft VBScript compilation error: Cannot use parentheses when calling a
Sub

"Al Dunbar" wrote:

>
> "Paul" <Paul@discussions.microsoft.com> wrote in message
> news:61D3044F-9F7B-46B5-8C8C-1AB728729C15@microsoft.com...
> > Hi,
> >
> > I need to create a script that moves certain files from a folder and
> > places
> > them in a new directory. I need to use the Like operator because I only
> > know
> > the start of the file name. I want to move all of the files that start
> > with
> > Archive in the config folder.
> >
> > Here is the code, what should i change to get this working
> >
> > Dim fso
> > Set fso = CreateObject("Scripting.FileSystemObject")
> >
> > 'Copy xcacls.vbs to the users C:\windows\system32 directory
> > strFilePath = "C:\windows\system32\config"
> > strDestination = "\\resource\Installs\Backup\Event Logs"
> >
> > fso.movefile(strFilePath & "Like '%Archive%'", strDestination)
>
> The .movefile method expects the source argument to be a valid file
> specification, optionally with standard filesystem wildcards in the last
> item in the path - it does not have any sort of querying capability. Try
> this instead:
>
> fso.movefile(strFilePath & "\archive*.*", strDestination)
>
> /Al
>
>
>

Re: Moving Files by Michael

Michael
Tue Apr 10 18:35:01 CDT 2007

Paul wrote:
> I get this error message when trying to use ur code AL
>
> Microsoft VBScript compilation error: Cannot use parentheses when
> calling a Sub
>

Call fso.movefile(strFilePath & "\archive*.*", strDestination)

or (preferrably)...

fso.movefile strFilePath & "\archive*.*", strDestination


> "Al Dunbar" wrote:
>
>>
>> "Paul" <Paul@discussions.microsoft.com> wrote in message
>> news:61D3044F-9F7B-46B5-8C8C-1AB728729C15@microsoft.com...
>>> Hi,
>>>
>>> I need to create a script that moves certain files from a folder and
>>> places
>>> them in a new directory. I need to use the Like operator because I
>>> only know
>>> the start of the file name. I want to move all of the files that
>>> start with
>>> Archive in the config folder.
>>>
>>> Here is the code, what should i change to get this working
>>>
>>> Dim fso
>>> Set fso = CreateObject("Scripting.FileSystemObject")
>>>
>>> 'Copy xcacls.vbs to the users C:\windows\system32 directory
>>> strFilePath = "C:\windows\system32\config"
>>> strDestination = "\\resource\Installs\Backup\Event Logs"
>>>
>>> fso.movefile(strFilePath & "Like '%Archive%'", strDestination)
>>
>> The .movefile method expects the source argument to be a valid file
>> specification, optionally with standard filesystem wildcards in the
>> last item in the path - it does not have any sort of querying
>> capability. Try this instead:
>>
>> fso.movefile(strFilePath & "\archive*.*", strDestination)
>>
>> /Al

--
Michael Harris
Microsoft.MVP.Scripting



Re: Moving Files by Al

Al
Tue Apr 10 23:05:41 CDT 2007


"Michael Harris (MVP)" <mikhar.at.mvps.dot.org> wrote in message
news:eqGrhj8eHHA.4176@TK2MSFTNGP03.phx.gbl...
> Paul wrote:
>> I get this error message when trying to use ur code AL
>>
>> Microsoft VBScript compilation error: Cannot use parentheses when
>> calling a Sub
>>
>
> Call fso.movefile(strFilePath & "\archive*.*", strDestination)
>
> or (preferrably)...
>
> fso.movefile strFilePath & "\archive*.*", strDestination

Quite right. I just copied Paul's code without noticing that little
syntactical problem.

/Al

>> "Al Dunbar" wrote:
>>
>>>
>>> "Paul" <Paul@discussions.microsoft.com> wrote in message
>>> news:61D3044F-9F7B-46B5-8C8C-1AB728729C15@microsoft.com...
>>>> Hi,
>>>>
>>>> I need to create a script that moves certain files from a folder and
>>>> places
>>>> them in a new directory. I need to use the Like operator because I
>>>> only know
>>>> the start of the file name. I want to move all of the files that
>>>> start with
>>>> Archive in the config folder.
>>>>
>>>> Here is the code, what should i change to get this working
>>>>
>>>> Dim fso
>>>> Set fso = CreateObject("Scripting.FileSystemObject")
>>>>
>>>> 'Copy xcacls.vbs to the users C:\windows\system32 directory
>>>> strFilePath = "C:\windows\system32\config"
>>>> strDestination = "\\resource\Installs\Backup\Event Logs"
>>>>
>>>> fso.movefile(strFilePath & "Like '%Archive%'", strDestination)
>>>
>>> The .movefile method expects the source argument to be a valid file
>>> specification, optionally with standard filesystem wildcards in the
>>> last item in the path - it does not have any sort of querying
>>> capability. Try this instead:
>>>
>>> fso.movefile(strFilePath & "\archive*.*", strDestination)
>>>
>>> /Al
>
> --
> Michael Harris
> Microsoft.MVP.Scripting
>
>



Re: Moving Files by Paul

Paul
Wed Apr 11 10:04:09 CDT 2007


Thank you for ur help. So I got it working except one piece of the puzzle.
The fso.folderexists doesnt seem to work when you dont use exact file names.
If i put in the exact name of the file it works. Is there anyway around
this. I posted by code below.

----------------------------------------------------------------------------------------------
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

strFilePath = "C:\Windows\system32\config\archive*.*"
strDestination = "\\resource\Installs\Backup\Event Logs"

'The If Statement isnt working
If fso.FileExists(StrFilePath) Then
fso.movefile strFilePath, strDestination
End If


Re: Moving Files by Al

Al
Thu Apr 12 19:14:50 CDT 2007


"Paul" <Paul@discussions.microsoft.com> wrote in message
news:A586EA3F-954B-45E9-9D70-B93BE3E3324E@microsoft.com...
>
> Thank you for ur help. So I got it working except one piece of the
> puzzle.
> The fso.folderexists doesnt seem to work when you dont use exact file
> names.
> If i put in the exact name of the file it works. Is there anyway around
> this. I posted by code below.
>
> ----------------------------------------------------------------------------------------------
> Dim fso
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> strFilePath = "C:\Windows\system32\config\archive*.*"
> strDestination = "\\resource\Installs\Backup\Event Logs"
>
> 'The If Statement isnt working
> If fso.FileExists(StrFilePath) Then
> fso.movefile strFilePath, strDestination
> End If

That approach works well in batch script, but not in vbscript. One of the
differences (though I don't know if this is significant here) is that
batch's "IF EXIST" does not specify that the thing being tested is assumed
to be a file - it could be a directory or even the NUL device.
FSO.FileExists, on the other hand, will return false if the thing that
exists by that name is a folder rather than a file.

IMHO, the approach is often used in batch because of the limitations on
error processing. Is there any reason why you could not simply do the copy
and ignore the "no such file" error, i.e.:

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

strFilePath = "C:\Windows\system32\config\archive*.*"
strDestination = "\\resource\Installs\Backup\Event Logs"

on error resume next
fso.movefile strFilePath, strDestination


/Al




Re: Moving Files by Paul

Paul
Fri Apr 13 08:52:03 CDT 2007

Thanks AL you the man!

"Al Dunbar" wrote:

>
> "Paul" <Paul@discussions.microsoft.com> wrote in message
> news:A586EA3F-954B-45E9-9D70-B93BE3E3324E@microsoft.com...
> >
> > Thank you for ur help. So I got it working except one piece of the
> > puzzle.
> > The fso.folderexists doesnt seem to work when you dont use exact file
> > names.
> > If i put in the exact name of the file it works. Is there anyway around
> > this. I posted by code below.
> >
> > ----------------------------------------------------------------------------------------------
> > Dim fso
> > Set fso = CreateObject("Scripting.FileSystemObject")
> >
> > strFilePath = "C:\Windows\system32\config\archive*.*"
> > strDestination = "\\resource\Installs\Backup\Event Logs"
> >
> > 'The If Statement isnt working
> > If fso.FileExists(StrFilePath) Then
> > fso.movefile strFilePath, strDestination
> > End If
>
> That approach works well in batch script, but not in vbscript. One of the
> differences (though I don't know if this is significant here) is that
> batch's "IF EXIST" does not specify that the thing being tested is assumed
> to be a file - it could be a directory or even the NUL device.
> FSO.FileExists, on the other hand, will return false if the thing that
> exists by that name is a folder rather than a file.
>
> IMHO, the approach is often used in batch because of the limitations on
> error processing. Is there any reason why you could not simply do the copy
> and ignore the "no such file" error, i.e.:
>
> Dim fso
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> strFilePath = "C:\Windows\system32\config\archive*.*"
> strDestination = "\\resource\Installs\Backup\Event Logs"
>
> on error resume next
> fso.movefile strFilePath, strDestination
>
>
> /Al
>
>
>
>