开发者

Excel-VBA Find a pdf file given a path

开发者 https://www.devze.com 2023-03-07 02:00 出处:网络
Problem: I need to know what files have been placed in a series of folders. I\'d like to catalog which files are there in each folder and be able to do check this whenever I want without having to man

Problem:

I need to know what files have been placed in a series of folders. I'd like to catalog which files are there in each folder and be able to do check this whenever I want without having to manually go into each folder. A sort of "syncing" of multiple files from different directories to a centralized catalog so that if I delete a file from a folder then the catalog will reflect the change.

I was hoping Excel could help with this. In short I want to be able to do this:

Filename     FilePath                     Exists

abc_4.23.11  C:\4-23-11\abc_4.23.11.pdf   *True/False*

Details/Assumptions:

The main directory won't change for a file. So File "abc.pdf" will always be in the same folder.

Let's assume Folder 1 has the following convention:

Folder Name: mm-dd-yy (i.e 4开发者_如何转开发-30-11)

Contents of Folder 1: A series of other subfolders, we'll call these using letters so Folder A, Folder B, Folder C...Folder Z.

Inside each subfolder is a pdf file which I need to confirm that it is there.

Let me know if there's any questions.

Thanks a million!


This might help to start with:

Sub ListAllFiles() 
Dim fs As FileSearch, ws As Worksheet, i As Long 
Set fs = Application.FileSearch 
With fs 
    .SearchSubFolders = False ' if you want to search the sub folders also, set to true
    .FileType = msoFileTypeAllFiles 'change this depending on the types of files you would like to filter
    .LookIn = "C:\"  'this will be the search location
    If .Execute > 0 Then 
        Set ws = Worksheets.Add 
        For i = 1 To .FoundFiles.Count 
            ws.Cells(i, 1) = .FoundFiles(i) 
        Next 
    Else 
        MsgBox "No files found" 
    End If 
End With 
End Sub

What you would need to do through is create the bit where it checks if the files still exists. Hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消