+ Reply to Thread
Results 1 to 6 of 6

Dir function question

  1. #1
    Registered User
    Join Date
    10-26-2012
    Location
    Springdale, Arkansas
    MS-Off Ver
    Excel 2007
    Posts
    13

    Dir function question

    I would like to iterate through folders. I'm attempting to do so using the dir function. Here is the code I tried:


    Please Login or Register  to view this content.
    I can't understand why the first two FolderName strings that are displayed with MsbBox are "." and ".." (one period and then two periods) before it even gets to the first folder name.

    Also, it not only returns the desired folder names but also the names of the Excel workbooks that are in the same main folder. How do I get the dir function to only return folder names?
    Novice Programmer

  2. #2
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    863

    Re: Dir function question

    Will this do the trick?
    Please Login or Register  to view this content.
    Harry.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Dir function question

    >>Deleted.

  4. #4
    Registered User
    Join Date
    10-26-2012
    Location
    Springdale, Arkansas
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Dir function question

    No, that didn't change anything.

  5. #5
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Dir function question

    "." and ".." are standard DOS folder 'shortcuts'. Type in DIR in a command window and you will see them. "." is the current directory and ".." is the parent directory. In VBA, use an If statement to ignore them and GetAttr to check if the file returned by Dir is a directory:

    Please Login or Register  to view this content.
    Post responsibly. Search for excelforum.com

  6. #6
    Registered User
    Join Date
    10-26-2012
    Location
    Springdale, Arkansas
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Dir function question

    Quote Originally Posted by Chippy View Post
    "." and ".." are standard DOS folder 'shortcuts'. Type in DIR in a command window and you will see them. "." is the current directory and ".." is the parent directory. In VBA, use an If statement to ignore them and GetAttr to check if the file returned by Dir is a directory:
    Thanks. That did the trick.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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