[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Need help with a VBScript

Posted on 2003-11-12
9
Medium Priority
?
274 Views
Last Modified: 2010-05-01
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.
0
Comment
Question by:geekoid2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9731297
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
 

Author Comment

by:geekoid2
ID: 9731952
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9732093
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Expert Comment

by:EDDYKT
ID: 9733277
>>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
 

Author Comment

by:geekoid2
ID: 9733466
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9733585
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9734069
AFAIK

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


8->
0
 

Author Comment

by:geekoid2
ID: 9735820
Oh, I though he was sneezing or something verbally.
0
 
LVL 59

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 9737885
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question