Check for disk space in VBScript

I have a VBScript scheduled to move some backup files from one server to another on a nightly basis. I'd like to be able to check the destination disk for available space before the transfer begins. Is there a way to do this in a VBScript? If so, how?
LVL 10
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.

Dim fso, oDrive

Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set oDrive = fso.GetDrive("C")

WScript.Echo "Free KB: " & FormatNumber(oDrive.FreeSpace/1024, 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
(That will get the free space available on C drive)
cjones_mcseAuthor Commented:
Sorry, I was a little to vague in the initial question. I can up the points if I need to. How would I compare this to the size of the transfer so that it would exit rather than attempt to transfer and then fail because there is not enough space?

Here's the script I'm using:

Option Explicit
Dim strScriptName
Dim strScriptDir
Dim strXlsName
Dim strRemoveName

strScriptName = "desktop.vbs"
strScriptDir = "d:\windows\desktop"
strXlsName = "desktops.xls"
strRemoveName = "OldLinks"

Dim wshShell

' Initialize shell and retreive path to desktop
Set wshShell = WScript.CreateObject("WScript.Shell")

Dim DesktopPath

'Initialize an instance of the file system object
Dim fs
Set fs= WScript.CreateObject("Scripting.FileSystemObject")

Dim wshArgs
Set wshArgs=Wscript.Arguments

dim i,srcfull

srcfull = "\\rslca1-tidead\sharepoint\Tide_Backup"

call Process (srcfull)


sub Process (srcfull)

dim desthome,srcpath,srcitem,destpath,destfolder,destsave,ok

     desthome="D:\backups\TIDEWEB"   'base for storage

     srcpath = fs.GetParentFolderName(srcfull)
     srcitem = fs.getBaseName(srcfull)

     destpath = desthome
     destfolder = srcitem
     destsave = fs.Buildpath(destpath,destfolder)
     'on error resume next
     'copy files
     ok = true
     ok =  MoveFiles(srcfull,destsave)
     if not ok then
          wscript.echo "Move failed.... Why ??"
     end if

end sub

function MoveFiles(srcfolder,destfolder)
     dim ok,f,osh
     on error resume next

     set osh = CreateObject( "WScript.Shell" )
     osh.Run "attrib -r -s -h " & srcfolder & " /s",1,true
     'need to check for folder exist
     'if yes , continue
     'if no , get parent
     'if exist parent
     'Set f = fs.GetFolder(srcfolder)
     'f.Copy destfolder,true

     'Attributes set
     Makepath destfolder
     if err.number >0 then
          Wscript.echo "MakePath failed" & vbcrlf & err.number & _
    " " & err.description
          exit function
     end if

     'Path Created

     fs.CopyFolder srcfolder,destfolder,true

     if err.number >0 then
          wscript.echo "Copy failed" & vbcrlf & err.number & _
    " " & err.description

          'delete files copied to destin
          exit function
     end if

     'Transfer complete

     'delete files
     fs.deletefolder srcfolder,true

     if err.number >0 then
          'files copied OK so notify user
          Wscript.echo "Files copied but could not be deleted !!!" & _
    vbcrlf & "Delete manually" & vbcrlf & err.number & "!" & _
          Movefiles=ok : exit function
     end if
     wscript.echo "Backup files have been copied from " & vbcrlf & _
     srcfolder & " to " & destfolder & "." & vbcrlf & _
     "Source files have been deleted." & vbcrlf & _
     DATE() & " " & TIME()


end function

sub makepath(destfolder)

     if fs.folderexists(destfolder) then
          exit sub

     end if
     if fs.folderexists(fs.GetParentFolderName(destfolder)) then
          fs.CreateFolder destfolder
          MakePath fs.GetParentFolderName(destfolder)
     end if

     MakePath destfolder

end sub
cjones_mcseAuthor Commented:
Okay, well, you answered the initial question. I'll just award the points and open a new question for the rest of this.

Thanks, if you wait a little more, tomorrow I will take a look at your code and see if I can help
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.