+ Reply to Thread
Results 1 to 4 of 4

Getting list of files from folder and subfolder

  1. #1
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Getting list of files from folder and subfolder

    So a new disaster today! I have the following code:

    Please Login or Register  to view this content.
    And it actually works - well sort of. If I look at the results in some cases it gives the same file twice (even though there is only 1 in the folder). More worryingly though it seems to miss complete folders at the same level as the ones it returns. As always I feel like I'm doing something wrong. Am I or is this sort od code hit and miss (although it's been missing the same way all day long).

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,286

    Re: Getting list of files from folder and subfolder

    This will create a a list of folders and files in columns A and B of the active sheet - you can list any other file attributes you need in other columns.....

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Getting list of files from folder and subfolder

    That seems to work - as in it at least has the first file I know was missing in the original list. CAn you tell me what the difference was?

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,286

    Re: Getting list of files from folder and subfolder

    I think it was because you were processing subfolders first and launching a new FSO for each, which meant that your code would go to the deepest folder in the path, and find the files, then step out one level and reprocess it again - so however many folders you had, you would get that many multiples. I had 7 lisitngs for every file, because I had 7 sub folders in my path. But, I think it never fully processed the lowest level of sub-folder, so those files were missing - you needed to move your files loop outside your sub-folder loop:

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 04-20-2017 at 01:37 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 14
    Last Post: 09-18-2016, 08:13 AM
  2. Replies: 2
    Last Post: 12-29-2015, 04:19 AM
  3. Replies: 0
    Last Post: 09-18-2015, 03:20 AM
  4. Replies: 12
    Last Post: 03-09-2015, 05:52 PM
  5. find list of files in different subfolder and move them to one folder
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-12-2015, 05:35 AM
  6. [SOLVED] Delete folder and subfolder OKB Files
    By laxmanann in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-11-2014, 02:05 PM
  7. Return files from a folder without Subfolder
    By EMoe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2009, 11:33 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1