Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    When right clicking a folder - "Properties", the General tab ao. displays "Contains" and then states counts of folders and files.

    How are those easily counted - would anyone willing to share, have a snippet that does this job fast and efficient?

    Been looking to use File System Object (FSO), but I believe there must be other ways that are easier and more effecient as well??

    Would imagine there was some kind of Win API function available for this kind of task...?
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Working with FileSystemObject is quite easy:

    Dim fso As New Scripting.FileSystemObject
    Dim fld As Scripting.Folder
    Dim lngSubFolderCount As Long
    Dim lngFileCount As Long
    Set fld = fso.GetFolder("C:\MyFolder")
    lngSubFolderCount = fld.SubFolders.Count
    lngFileCount = fld.Files.Count

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Hans,

    Thanks - the "scripting" references you got set - are they to the "Microsoft Scripting Runtime" (scrrun.dll)??

    Dim fso As New Scripting.FileSystemObject
    Dim fld As Scripting.Folder


    Got one main folder, with 350+ subfolders. Each subfolder have at least the single file I'm looking for (to update) directly in it. But some have had another subfolder added, so that I need to find the file to update in the subfolder instead.

    Thus, I'm trying to see, if I with the "LookIn" and "SearchFolders" (http://msdn.microsoft.com/en-us/library/aa210046(office.11).aspx) - or any other method, can find an easy way to get a tree structure to traverse.

    Subsequently I'll need to write the changes to the files in a log file. With "change done", "file name" and "folder".
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Scripting indeed refers to the Microsoft Scripting Runtime library - you need to set a reference to it in Tools | References...

    In Office 2003 VBA you can use the Application.FileSearch object to search for files in a folder structure, but keep in mind that this has been removed in Office 2007, so if you plan on upgrading anytime soon, it's better to avoid using Application.FileSearch.

  5. #5
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I'll try to keep that in mind.
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  6. #6
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    [quote name='Henrik Ryberg' post='781662' date='25-Jun-2009 07:51'][/quote]
    Take note Henrik, that the code as provided by Hans counts only the files and folders at the top level within the specified folder.
    Regards
    Don

Posting Permissions

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