We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Need help Vb script copy fonts

Dutchict
Dutchict asked
on
Medium Priority
931 Views
Last Modified: 2012-05-06
Can you help me to create the following script

The users get a error when the font exist.
How can i make a if else, that verifying that the files exist?
If the fonts exist then nothing.
else copy the fonts

Maybe it's better to create a array for the fonts.

Const FONTS = &H14&
 
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FONTS)
 
	objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRABK.TTF"
	objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRABKIT.TTF"
	objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRADM.TTF"
	objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRADMCN.TTF"
	objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRADMIT.TTF"
	objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRAHVIT.TTF"
	objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\framd.ttf"
	objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\framd__0.ttf"
	objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRAMDCN.TTF"
	objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRAMDIT0.TTF"
	objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\framdit.ttf"

Open in new window

Comment
Watch Question

Commented:
This revision only copy files that don't exist in the destination.


Const FONTS = &H14&
 
strSource = "\\2k3svr02\netlogon\deploy_fonts\fonts"
arrFiles = Array("FRABK.TTF", "FRABKIT.TTF", "FRADM.TTF", "FRADMCN.TTF", "FRADMIT.TTF", _
    "FRAHVIT.TTF", "framd.ttf", "framd__0.ttf", "FRAMDCN.TTF", "FRAMDIT0.TTF", "framdit.ttf")
 
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FONTS)
 
For Each strFile in arrFiles
    Set objFolderItem = objFolder.ParseName(strFile)
    
    If objFolderItem is nothing Then
        objFolder.CopyHere strSource & "\" & strFile
    End If
Next

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Having all the fonts in an array would definitely ease things a lot.

The simple solution would be adding the line:
on error resume next
in the beginning of the script, this will ignore all the errors. After the file copy you can turn error reporting on if you need to run more operations by adding the line:
on error goto 0

Simple solution would be:
if not fso.FileExists(objFolder.self.path+"\FRABK.TTF") objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRABK.TTF"
 
if not fso.FileExists(objFolder.self.path+"\FRABKIT.TTF") objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRABKIT.TTF"

Open in new window

Sorry, forgot the then keyword
if not fso.FileExists(objFolder.self.path+"\FRABK.TTF") then objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRABK.TTF"
 
if not fso.FileExists(objFolder.self.path+"\FRABKIT.TTF") then objFolder.CopyHere "\\2k3svr02\netlogon\deploy_fonts\fonts\FRABKIT.TTF"

Open in new window

Author

Commented:
I'm an beginner in scripting understand the solution.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.