Need help with a VBScript

Hello all, what I need is a VBScript or just a function for that matter but it has to work in a .vbs file.

What I need it to do is take an argument that is a path to a specific directory on my server. Within that directory there are subfolders and files. I need to look for specific files and when they are found I need to overwrite them with the updated version of these files. The directory structure is different on each server but the path is always the same. What I'm am doing is updating icon files for office programs. Our GPO's in the domain control what the user has for icons on their desktop so there are stored on the server. We are about to upgrade to Office 2003 so the icons need to be updated as well. So the script has to be able to read through the directory where we keep them and when it finds them replace them with the newer version. A function would work better because I have to do it for Word, Excel, PowerPoint, ect... and it would be easier if I could pass the function the argument of which one I'm looking for.

Something Like:

Public Sub changefile(path, file)
     getfolder(path)
     searchfolder(path) for (file)
     If (file) exsist then overwrite with (newfile)
     else exit sub
     Do until there are no more files to change
exit sub

Obviously this isnt proper code it was just to help show what I need it tp do.

Points go to the first code that works.

Thanks.
geekoid2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richie_SimonettiIT OperationsCommented:
first approach (without parameters and path aand filenames hard-coded):

Call CopyIfNewer()




sub CopyIfNewer()
Dim fso
Set fso = CreateObject("scripting.filesystemobject")

Dim fTarget, fSource
Set fTarget = fso.GetFile("c:\Fmc\Register\FmcRegCorp.mde")
Set fSource = fso.GetFile("\\lnxsui\comun\Software\FmcRegister\Updates\FmcRegCorp.mde")
If fSource.DateCreated > fTarget.DateCreated Then
    fTarget.Delete True
    fSource.Copy "c:\Fmc\Register\", True
End If
End Sub
0
geekoid2Author Commented:
This is close but it assumes that the target file is known. What I asked is that it takes a tageted path and then searches through this path to determine if the files exist. If the file does exist then copy it with the new version. I don't want it to test the DateCreated property I only need to verify that the file is there and if so then copy.
0
Richie_SimonettiIT OperationsCommented:
I understood what you need, i posted a "FIRST approach" as i said.
AFAIK, it is not possible to pass command line args to vbscript file. Sorry. I will keep searching anyway.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

EDDYKTCommented:
>>it is not possible to pass command line args to vbscript file

Dim oArgs, ArgNum, ArgServerList

Set oArgs = WScript.Arguments
ArgNum = 0
While ArgNum < oArgs.Count

      Select Case LCase(oArgs(ArgNum))
            Case "--help","-?":
                  Call DisplayUsage
            Case Else:
                  Call DisplayUsage
      End Select      

      ArgNum = ArgNum + 1
Wend

Sub DisplayUsage
      WScript.Echo "Usage: ..."
      WScript.Quit (1)
End Sub
0
geekoid2Author Commented:
You most certainly can pass command line arguments in a script file. If you don't know how you just need to say so. I wont hold it against you, lol.

This is going to be what I use to copy the file once it's found.

Public Sub copynewicon(pathto)

      Dim pathfrom

      pathfrom = "D:\Test2\New.txt"
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set f = fso.GetFile(pathfrom)
      f.Copy (pathto)
End Sub

copynewicon "D:\Test\New.txt"

What I need is the routine that takes a path i.e... D:\path and then searches through all of the files within the path and each time it comes across the file replace it with the new one.
0
Richie_SimonettiIT OperationsCommented:
just take a close look to my comment before go further, i said:
"....
AFAIK, it is not possible to pass command ...."

As
Far
As
I
Know
0
EDDYKTCommented:
AFAIK

it is really a short hand that I've never seen before


8->
0
geekoid2Author Commented:
Oh, I though he was sneezing or something verbally.
0
Julian HansenCommented:
As I mentioned in my post to the previous posting copying short cut files (if that is what you are doing) rather than creating them on the machine is not such a good idea. But if you want to do it that way then you need a method to parse a directory sub-tree. The easiest way to do this (arguably not the most efficient) is to use a recursive search. The following MSDN article will tell you how to do this

HOW TO: Recursively Search Directories by Using FileSystemObject
PSS ID Number: 185601

Basically, you take a path and a filename as parameters, use the path as a starting point and recursively search for the file. If you find it you replace it

Sub SomeFunction(path, file)
   filepath = Find(path, file)
   if filepath <> "" then
        Copy(SourceFile, filepath)
   end if
end sub

The Find function you can get from the article.

In your post you don't say where the function would get the value for newfile. If you post that information I can post more comprehensive code
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.