Read External File Properties

VijaySM

New Member
Joined
Nov 26, 2015
Messages
7
Hi Excel Experts

http://www.mrexcel.com/forum/excel-questions/73458-read-external-file-properties-date-created-using-visual-basic-applications-2.html


I am taking a list of files in a network folder and using the code in the above link. Since, the folder has large number of files the code stops when the excel row limit is reached. So, I want to include some code so that if the listing of files in a folder exceeds the row limit, it should create a new sheet and continue from where it ended in previous sheet.

Regards
VijaySM
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Sir

Thank you for your suggestion and I have seen that link, but since I am new to VBA and I am unable to modify the code in the link which lists the files in folder but stops when the last row is reached. I also searched the web but have not found any implementation like this. Some of the codes just try to split the large data files.

Regards
VijaySM
 
Upvote 0
Hi Excel Experts

I am posting again in this thread as I am able to get the answer to this specific problem on the web as well as other forums where I asked the same question. Please suggest a solution as I am unable to do it myself.

http://www.mrexcel.com/forum/excel-...ay-listing-folders-subfolders-contents-2.html

I have read this post and want to adapt this code for my use with Thanks to user shg for posting it so that everyone can be helped. My question is that if there are more files than the excel row limit, I want the code to insert another sheet and continue listing the files. I have tried to modify the above code but not able to achieve the desired result. Hope someone here or shg himself can help solve this problem. The modified code is as below. sometimes I get error when ifile = 1048577 or inserts new blank sheet. I tried to reset the counter as suggested in another forum, but it gives wrong file count i.e. number of files after the row limit and no files are listed.
Code:
Option Explicit

Sub ListFiles()
    Dim sPath      As String


    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Select directory"
        .InitialFileName = ThisWorkbook.Path & "\"
        .AllowMultiSelect = False
        If .Show = 0 Then Exit Sub
        sPath = .SelectedItems(1) & "\"
    End With


    NoCursing sPath, Range("A1")
End Sub


Sub NoCursing(ByVal sPath As String, rOut As Range)
    ' lists file name, size, and date for the files in and below sPath
   ' in columns A:C of rOut


    ' attribute mask
   Const iAttr    As Long = vbNormal + vbReadOnly + vbSystem + vbDirectory
    Dim jAttr      As Long        ' file attributes
   Dim col        As Collection  ' queued directories
   Dim iFile      As Long        ' file counter
   Dim sFile      As String      ' file name
   Dim sName      As String      ' full file name
   Dim fSec        As Single      ' seconds since midnight


    Dim maxRows As Long
    Dim sheetNumber As Integer
    maxRows = 1048576


    With rOut.Range("A1:C1").Resize(rOut.Worksheet.Rows.Count - rOut.Row + 1)
        .ClearContents
        .Rows(1).Value = Split("File,Date,Size", ",")
    End With


    Application.ScreenUpdating = False
    fSec = Timer


    If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
    Set col = New Collection
    col.Add sPath


    Do While col.Count
        sPath = col(1)
On Error Resume Next
        sFile = Dir(sPath, iAttr)


        Do While Len(sFile)
            sName = sPath & sFile


            On Error Resume Next
            jAttr = GetAttr(sName)


            If Err.Number Then
                ' You can't get attributes for files with Unicode characters in
               ' the name, or some particular files (e.g., "C:\System Volume Information")
               Debug.Print sName
                Err.Clear


            Else
                On Error GoTo 0
                If jAttr And vbDirectory Then
                    If Right(sName, 1) <> "." Then col.Add sName & "\"


                Else
                    iFile = iFile + 1
                    If (iFile And &H3FF) = 0 Then
                        Application.StatusBar = sMsg(iFile, Timer - fSec, col.Count)
                        DoEvents
                    End If
                   
                    If iFile = maxRows Then
                      sheetNumber = sheetNumber + 1
                      ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
                      ActiveSheet.Name = "Sheet-" & sheetNumber
		iFile = 1
                    End If


                  iFile = iFile + 1
                   
                    rOut.Range("A1:C1").Offset(iFile).Value = Array(sName, _
                                                                    FileDateTime(sName), _
                                                                    FileLen(sName))
                End If
            End If
            sFile = Dir()
        Loop
        col.Remove 1
    Loop


    iFile = iFile + 1
    rOut.Offset(iFile).Value = sMsg(iFile - 1, Timer - fSec, col.Count)
    rOut.CurrentRegion.Sort Key1:=rOut.Range("A1"), Header:=xlYes
    Columns.AutoFit
    Application.StatusBar = False
    Application.ScreenUpdating = True
End Sub


Function sMsg(nFile As Long, fSec As Single, nCol As Long) As String
    sMsg = "  Files listed: " & Format(nFile, "#,##0") & _
          "  ET: " & Format(fSec / 86400, "h:mm:ss") & _
          "  Files/s: " & Format(nFile / fSec, "0") & _
          "  Directories queued: " & nCol

End Function

Please anyone help me find a solution to this problem.

Thanks
 
Upvote 0
Hi Friends -
I had asked this question in this forum as in the below link, but I have not got any reply. Can any one of you please help me out.

http://www.mrexcel.com/forum/excel-questions/904942-list-all-files-server-folder-using-dir.html

The above code which is by user shg is from this link

http://www.mrexcel.com/forum/excel-...-way-listing-folders-subfolders-contents.html

Please any one of the excel experts or user shg himself, if you happen to see please reply. I am eagerly waiting for a solution.

Thanks
 
Upvote 0
Hi Friends -
Please help me with this problem.
User "shg", please respond to my query as I am unable to solve it regardless of what modification I have done so for using your code.

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top