Replace file if smaller in size

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Am very new to vbscript and am trying to piece together some code that
will check the size of a file on a users Home drive and replace it
with a file from the C:\ drive if it is 3mb. Can one of the guru's in
the group put me right..

Thanks in advance...


______________________________

Option Explicit
On Error Resume Next
'
Dim FolderPath
Dim objFSO
Dim objFolder
Dim colFiles
Dim objFile

FolderPath = "H:\foldername"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("H:\foldername")
Set objFile = "file.txt"

'Check if user has folder or not
If CheckFolderExists("H:\foldername") Then
Else
End If

'Reference the file.txt file if exists
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("H:\foldername\file.txt") Then
Set objFolder = objFSO.GetFile("H:\foldername\file.txt")
Else
End If

'Conditional overwrite if file.txt if is less than 3 mb

If objFile.size > 3000 kb Then
objFSO.CopyFile "C:\program files\prog\folder" , "H:\folder",
OverwriteExisting
Else
End If
_____________________________
Wscript error says "expected "then" on this line

If objFile.size > 3000 kb Then

.



Relevant Pages

  • Re: Replace file if smaller in size
    ... Dim objFolder ... Dim objFile ... Set objFSO = CreateObject ... 'Conditional overwrite if file.txt if is less than 3 mb ...
    (microsoft.public.scripting.vbscript)
  • Re: ASP Script Hangs
    ... > Set objFSO = Server.CreateObject ... > Dim objFolder ... > Set objFolder = objFSO.GetFolder ... > Dim objFile ...
    (microsoft.public.inetserver.asp.general)
  • Re: IP Range Scanner version 3
    ... Dim objFSO, objTextFile, objWMIService, colItems, objNet, objItem, i, ii, colIESettings ... Set objFSO = CreateObject ... Set colUserName = objWMIService.ExecQuery ... ' Though there are other ways to ping a computer, Win2K, ...
    (microsoft.public.scripting.vbscript)
  • ASP Script Hangs
    ... Set objFSO = Server.CreateObject ... Dim objFolder ... Set objFolder = objFSO.GetFolder ... Dim objFile ...
    (microsoft.public.inetserver.asp.general)
  • Re: Scheduled task
    ... Dim oSqlConn, objPrintJob, intTotalPages, strComputer, objWMIService ... Set colPrintJobs = Nothing ... For Each objPrintJob In colPrintJobs strTextBody = strTextBody & TabData ... Set objFSO = CreateObject ...
    (microsoft.public.scripting.vbscript)