none
having the laste modification date and the size of a file RRS feed

  • Question

  • Hello all;

    actually I'm using a VBA script to load a name of files stored in a specific folder, and also to generate an hypertext link top each file.

    the file name is generated on the column A, the hypertext link is generated in column B.

    i want to add to this script the "laste modification date' on the C column and the "file size" on the D column.

    hereunder the script that i'm using

    Public nb As Long
    Sub Bouton1_Cliquer()
    Dim chemin As String
        nb = 0
        chemin = "N:\Folder1"
        Lister chemin
    End Sub
    
    Public Function Lister(chemin As String)
    Dim fs, Rep, f As Variant, NewRep As String, Nomfich As String
        Set fs = CreateObject("Scripting.FileSystemObject")
            Lister = fs.GetFolder(chemin).Files.Count
            Nomfich = Dir(chemin & "\*.*")
        
        Do While Nomfich <> ""
            nb = nb + 1
            Cells(nb, 1) = Nomfich 'liste dans la feuille de calculs active
            Cells(nb, 2).Hyperlinks.Add Cells(nb, 2), chemin & "\" & Nomfich
            Nomfich = Dir()
        Loop
        'Pour chaque sous-répertoire, appel récursif de Lister
        For Each Rep In fs.GetFolder(chemin).SubFolders
            NewRep = Lister(Rep.Path)
        Next Rep
    End Function
    
    

    Please can somebody help modifying it and includes the function that I'm looking for?

    Thursday, May 26, 2016 2:55 PM

All replies

  • This is an example of how you do it.

    Sub Example()
      Dim fso As New Scripting.FileSystemObject  ''Add reference to Microsoft Scripting Runtime
      Dim f As File
      Dim d As Date
      Dim s As Long
      
      Set f = fso.GetFile("C:\temp\myfile.txt")
      d = f.DateLastModified
      s = f.Size
      Debug.Print "Date: " & d & ", Size: " & s
    End Sub

    Thursday, May 26, 2016 3:37 PM
  • Try the 'File Manager' from the link below.

    http://www.learnexcelmacro.com/wp/download/

    That will do all you want and more.


    MY BOOK

    • Proposed as answer by ryguy72 Thursday, May 26, 2016 5:37 PM
    Thursday, May 26, 2016 5:35 PM