+ Reply to Thread
Results 1 to 6 of 6

How to find file size of network drives?

Hybrid View

  1. #1
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    How to find file size of network drives?

    How can I get the file sizes of network drives? Filelen() is not recognizing network names. Thanks for any help.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to find file size of network drives?

    Hello schulzy175,

    This works on my local network. Give it try on yours.

    ' Written:  January 24, 2018
    ' Author:   Leith Ross
    
    Function GetFileSize(ByVal FolderPath As Variant, ByVal Filename As Variant)
    
        Dim File   As Object
        Dim Folder As Object
        Dim oShell As Object
            
            Set oShell = CreateObject("Shell.Application")
            
            Set Folder = oShell.Namespace(FolderPath)
            
                If Folder Is Nothing Then
                    MsgBox """" & FolderPath & """ Not Found.", vbOKOnly + vbCritical
                    Exit Function
                End If
            
            Set File = Folder.ParseName(Filename)
            
                If File Is Nothing Then
                    MsgBox "The File """ & Filename & """ was Not Found.", vbOKOnly + vbCritical
                    Exit Function
                End If
            
            GetFilesize = Folder.GetDetailsOf(File, 1)
            
    End Function
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: How to find file size of network drives?

    Hi schulzy175,

    Based on this early binding FileSystemObject example I written the following late binding equivalent:

    Option Explicit
    Sub Macro1()
    
        Dim objFSO   As Object
        Dim objDrive As Object
        Dim dblSpace As Double
        
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objDrive = objFSO.GetDrive("C:") '<- Change to the relevant drive letter you're interested in
        
        dblSpace = Round(objDrive.TotalSize / 1073741824, 0) 'Converting bytes to GB
        
        MsgBox "The total size of " & objDrive.DriveLetter & " is " & dblSpace & "GB"
        
        Set objDrive = Nothing
        Set objFSO = Nothing
    
    End Sub
    HTH

    Robert
    Last edited by Trebor76; 01-24-2018 at 07:48 PM.
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: How to find file size of network drives?

    Much thanks for the codes, but I've already had it working locally, but I am trying to replace "C:" with a network name. i.e. "\\MYNETWORK" OR "\\MYNETWORK\FOLDER". My apologies for not being clearer in the first post.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to find file size of network drives?

    Hello schulzy175,

    So you want to convert a mapped drive letter to it is UNC path?

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: How to find file size of network drives?

    Does this work for you ?
    Sub tst()
        MsgBox GetUNC("C:")
    End Sub
    
    Function GetUNC(strMappedDrive As String) As String
        Dim strDrive As String
        Dim strShare As String
        With CreateObject("scripting.filesystemobject")
            strDrive = .GetDriveName(strMappedDrive)
            strShare = .Drives(strDrive & "\").ShareName
        End With
        GetUNC = Replace(strMappedDrive, strDrive, strShare)
    End Function
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 06-10-2019, 01:38 PM
  2. [SOLVED] copying between network drives using UNC
    By billyjo182 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2017, 06:26 PM
  3. [SOLVED] Ignore Network Drives if not available
    By JamesT1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-13-2014, 12:03 PM
  4. Network Drives
    By Keith in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 07-06-2006, 05:40 PM
  5. [SOLVED] Linked cells and Mapped Network Drives
    By James McDowell in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-10-2006, 01:45 PM
  6. opening files on network drives via a brouser
    By Juuljus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-20-2005, 09:50 AM
  7. Network Drives
    By Nick S in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2005, 11:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1