• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to Get the file name in a folder and sub folders and the no of files

Balajisx

Member
Hi All,

I am looking for a macro code that should do the below things.

o To fetch the file names and the count of files under a parent folder.

o The Parent folder will bear multiple sub folders and these subfolders will bear images in PDF, TIF …etc. formats; The tool will need to list down all the files, its count and its format.

o The tool should have the “source” and “destination”, path. The “Copy”, “Move”, “Delete” function should be included in the tool. This will help us to move the defined files to be moved, copied or deleted that are listed in the tool.

Kindly help me on this.

Regards,
Balajisx
 
Here is a starting point. This VBA will list all files in a provided path as well as the last modified date and time and the size of the file.
Code:
Sub ListAllFile()

    Dim objFSO As Object
    Dim objFolder As Object
    Dim objFile As Object
    Dim ws As Worksheet
    Dim sPath As String
    Dim lrA As Long
    Dim lrB As Long

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set ws = Worksheets.Add

    'Get the folder object associated with the directory
    sPath = InputBox("What is the full Path to Search?")
    Set objFolder = objFSO.GetFolder(sPath)
    ws.Cells(1, 1).Value = "The files found in " & objFolder.Name & " are:"
    ws.Cells(1, 2).Value = "The files found have modified dates:"
    ws.Cells(1, 3).Value = "The file Size is:"

    'Loop through the Files collection
    For Each objFile In objFolder.Files
        lrA = Range("A" & Rows.Count).End(xlUp).Row
        lrB = Range("B" & Rows.Count).End(xlUp).Row
        ws.Range("A" & lrA + 1).Value = objFile.Name
        ws.Range("B" & lrB + 1).Value = objFile.DateLastModified
        ws.Range("C" & lrB + 1).Value = objFile.Size
    Next
    'ws.Cells(2, 1).Delete
    'Clean up!
    Set objFolder = Nothing
    Set objFile = Nothing
    Set objFSO = Nothing

End Sub
 
Hi Thank you for your reply. I have created a macro tool which helps me to get the folder name and the parent folder path. Now I need a code which helps me to move or copy or delete files from a specified folder. In Column D I have given data validation. If I click the buttons on the top , based on the cell value it should be moved or copied or deleted. Please help me on this. Appriciate your help. Attached is the tool for your reference.
 

Attachments

  • File Listing Tool -V1.xlsm
    21.5 KB · Views: 16
o To fetch the file names and the count of files under a parent folder.

o The Parent folder will bear multiple sub folders and these subfolders will bear images in PDF, TIF …etc. formats; The tool will need to list down all the files, its count and its format.

o The tool should have the “source” and “destination”, path. The “Copy”, “Move”, “Delete” function should be included in the tool. This will help us to move the defined files to be moved, copied or deleted that are listed in the tool.
Hi, Balajisx!
I'd go for Windows Explorer... or any alternative program like:
http://alternativeto.net/software/windows-explorer/
Wheel was yet invented 4 thousand years ago.
Regards!
 
Hi SirJB7,

Thank you for your suggestion. I have created a template however I am looking for the code to copy or move or delete files from the folder. File name will start from column A9 file path is in C9 and Destination path Column D.
 
Back
Top