I want to know if I can copy the files in filelistbox1 to the target defined in Dir1.path, how can I measure if the target drive has enough hard disk space to store those files ?
Private Function DriveFreeSpace(DrivePath)
Dim fso, drv
Set fso = CreateObject("Scripting.FileSystemObject"
Set drv = fso.GetDrive(fso.GetDriveName(DrivePath))
DriveFreeKBytes = FormatNumber(drv.FreeSpace / 1024, 0)
End Function
Drive Path is the drive's path (e.g., "C:\". Note that the free space is returned in kilobytes. To get megabytes, divide by 1024000: FormatNumber(drv.FreeSpace / 1024000, 0)
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
This will give the total size of all files in any directory supplied to the function:
Private Function FileSize(ByVal FolderPath As String) As Long
Dim fso, fldr, fc, f
Set fso = CreateObject("Scripting.FileSystemObject"
Set fldr = fso.GetFolder(FolderPath & "\"
Set fc = fldr.Files
For Each f In fc
FileSize = FileSize + f.Size
Next
FileSize = FileSize / 1024
End Function
For a FileListBox named "File1", just call the function like this:
x = FileSize(File1.Path)
also, there were a couple of errors in the first function. Use this:
Private Function DriveFreeSpace(DrivePath) As Long
Dim fso, drv
Set fso = CreateObject("Scripting.FileSystemObject"
Set drv = fso.GetDrive(fso.GetDriveName(DrivePath))
DriveFreeSpace = drv.FreeSpace / 1024
End Function
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
I have an application in Windows 98SE PCs that encodes live TV in WMV format. I need to control every minute the free space on HD, because generates large files.
I used the function you suggest and works fine in Windows XP, but in W98SE shows an incorrect number which never changes.
Please tell me if there's some consideration in W98 with that function.
The FreeSpace method is only good for values up to 2gb.
Chip H.
____________________________________________________________________ Click here to learn Ways to help with Tsunami Relief If you want to get the best response to a question, please read FAQ222-2244 first
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.