Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default KeepITKool - Directory and File Size

Hey

Below is a response I got yesterday from KeepITkool.

I am getting the error that the file cannot be found when
the code executes this line: n = n + VBA.FileLen(sFile)


Can you tell me why. I have an inputbox asking for the
directory. When I type in C:\ABC, it runs the function.
Then in the function when it gets to that line of code, I
get that error. Do I need to reference a certain library?


Thanks for your help.
Todd

Subject: Finding byte info for files and folders
From: "keepITcool" Sent:
10/27/2004 3:50:38 PM




vba.FileLen(strPath) gives length in bytes
the prefix VBA is optional but included for clarity.


FirstMethod EXCLUDES the subdirs (pure VBA)
Second INCLUDES the subdirs (latebound Scripting
Runtime)

Both return bytes.
for KB : result \ 1024
for MB : result \ 1024 ^ 2


Function DirSize&(Optional sDir$, Optional sMask$ = "*.*")
Dim n&, sFile$
If sDir = vbNullString Then
sDir = VBA.CurDir$
End If
If VBA.Right$(sDir, 1) < Application.PathSeparator Then
sDir = sDir & Application.PathSeparator
End If

sFile = VBA.Dir$(sDir & sMask)
While sFile < vbNullString
n = n + VBA.FileLen(sFile)
sFile = VBA.Dir$()
Wend

DirSize = n

End Function

Function DirSizeFS&(Optional sDir$)
'INCLUDES SUBFOLDERSIZE
'http://msdn.microsoft.com/library/en-
us/script56/html/jsprosize.asp
If sDir = vbNullString Then
sDir = VBA.CurDir$
End If
With CreateObject("scripting.filesystemobject")
If .FolderExists(sDir) Then
DirSizeFS = .GetFolder(sDir).Size
End If
End With

End Function


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Todd Huttenstine"
wrote:

Hey guys

How do I find the byte info for files and folders?

The reason I want to do this is because i have a

directory
C:\test

Files in this directory can be added and/or changed.

How
would I check the size of that directory? Also how

would
I check the size of a file called "ABC.xls" in that same
directory?


Thanks
Todd Huttenstine



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default KeepITKool - Directory and File Size

Hey

I figured it out. I had to change the line from:
n = n + VBA.FileLen(sFile)
to:
n = n + VBA.FileLen(sDir & sFile)


Thanks again
Todd
-----Original Message-----
Hey

Below is a response I got yesterday from KeepITkool.

I am getting the error that the file cannot be found when
the code executes this line: n = n + VBA.FileLen(sFile)


Can you tell me why. I have an inputbox asking for the
directory. When I type in C:\ABC, it runs the function.
Then in the function when it gets to that line of code, I
get that error. Do I need to reference a certain library?


Thanks for your help.
Todd

Subject: Finding byte info for files and folders
From: "keepITcool" Sent:
10/27/2004 3:50:38 PM




vba.FileLen(strPath) gives length in bytes
the prefix VBA is optional but included for clarity.


FirstMethod EXCLUDES the subdirs (pure VBA)
Second INCLUDES the subdirs (latebound Scripting
Runtime)

Both return bytes.
for KB : result \ 1024
for MB : result \ 1024 ^ 2


Function DirSize&(Optional sDir$, Optional sMask$ = "*.*")
Dim n&, sFile$
If sDir = vbNullString Then
sDir = VBA.CurDir$
End If
If VBA.Right$(sDir, 1) < Application.PathSeparator Then
sDir = sDir & Application.PathSeparator
End If

sFile = VBA.Dir$(sDir & sMask)
While sFile < vbNullString
n = n + VBA.FileLen(sFile)
sFile = VBA.Dir$()
Wend

DirSize = n

End Function

Function DirSizeFS&(Optional sDir$)
'INCLUDES SUBFOLDERSIZE
'http://msdn.microsoft.com/library/en-
us/script56/html/jsprosize.asp
If sDir = vbNullString Then
sDir = VBA.CurDir$
End If
With CreateObject("scripting.filesystemobject")
If .FolderExists(sDir) Then
DirSizeFS = .GetFolder(sDir).Size
End If
End With

End Function


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Todd Huttenstine"
wrote:

Hey guys

How do I find the byte info for files and folders?

The reason I want to do this is because i have a

directory
C:\test

Files in this directory can be added and/or changed.

How
would I check the size of that directory? Also how

would
I check the size of a file called "ABC.xls" in that

same
directory?


Thanks
Todd Huttenstine



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Size With Macros Has Increased From Its Origina Size Fred Excel Discussion (Misc queries) 1 April 26th 08 12:24 AM
file save error: the file or directory cannot be created dublg Excel Discussion (Misc queries) 1 September 25th 06 07:07 PM
Excel should let me sort the file directory when saving a file Beanee70 Excel Discussion (Misc queries) 0 March 14th 06 07:03 AM
Combine all text file in directory into one file. Rich[_19_] Excel Programming 8 January 21st 04 04:09 PM
get path - save new file - same sub-directory as existing file tegger Excel Programming 2 October 21st 03 10:45 AM


All times are GMT +1. The time now is 02:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"