+ Reply to Thread
Results 1 to 4 of 4

Get name of subfolder

  1. #1
    Registered User
    Join Date
    12-14-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    26

    Get name of subfolder

    How can I get the name of a subfolder? I have a main folder that has subfolders named Photo_A, Photo_B, Photo_C, etc. Each subfolder will contain the same amount of files named according to their folder i.e Photo_A1, Photo_A2, Photo_B1, Photo_B2, etc. What I need to do is generate a list of all the file locations in all the folders. The naming convention of the folders and files will remain the same.


    Result:
    F:\New folder\30\Photo_A\JPEG\Photo_A1.jpg
    F:\New folder\30\Photo_B\JPEG\Photo_B1.jpg
    F:\New folder\30\Photo_C\JPEG\Photo_C1.jpg
    F:\New folder\30\Photo_A\JPEG\Photo_A2.jpg
    F:\New folder\30\Photo_B\JPEG\Photo_B2.jpg
    F:\New folder\30\Photo_C\JPEG\Photo_C2.jpg

    etc.....

    Steps of what I'm trying to do:

    1. Get the name of a subfolder, and get the portion of the string before _. In this case it would be "Photo".
    2. Look in one of the "Photo" folders and count the number of jpg files.
    3. I would then be able to generate a list in a loop for all the file locations.

    I thought it would be as simple as
    SourceFolder.subFolders.Item(1).Name

    I can't seem to figure out how to get the name of a subfolder and the file count in that folder.

    I know you can use a loop to count the number of subfolders. Looking in the properties of the main source folder, I can expand the SubFolders and see the count as 3. How can I do something similar for the subfolders?
    Last edited by roldy; 02-25-2019 at 10:36 PM.

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Get name of subfolder

    If you're looking to iterate folders and return a file listing perhaps the below code would suffice?

    This will return, to a new timestamped worksheet, the full file paths of any / all jpgs found below F:\New folder\30\

    Code Adapted from: https://analystcave.com/vba-dir-func...e-directories/

    modify the file path in initial subroutine as necessary etc...

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-14-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    26

    Re: Get name of subfolder

    The code works as far as listing all the files but it does not keep the order in which I need them as shown in my example. This list of files is used for zipping. My zip macro will take, in this example, the locations of 3 files which are to be zipped together....

    F:\New folder\30\Photo_A\JPEG\Photo_A1.jpg
    F:\New folder\30\Photo_B\JPEG\Photo_B1.jpg
    F:\New folder\30\Photo_C\JPEG\Photo_C1.jpg

    Then it takes the next 3 file locations. I have developed code to get this but I would like to know if there is a way to get the name of a sub folder. I can get the name within this loop

    Please Login or Register  to view this content.
    But I can't do it outside of it.

    Edit:
    I just realized that since the sub folder name is derived from the parent folder name, I can just use the parent folder name.
    Last edited by roldy; 02-26-2019 at 11:19 AM.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Get name of subfolder

    Hello roldy,

    Try this macro...

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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. look to subfolder
    By Siegfrid15 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-21-2016, 11:33 AM
  3. look to subfolder
    By Siegfrid15 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2016, 10:19 AM
  4. Replies: 0
    Last Post: 09-18-2015, 03:20 AM
  5. VBA code needed to move from Outlook 2010 subfolder to Symantec Vault subfolder
    By Marijke in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2014, 12:14 PM
  6. [SOLVED] Mkdir command button to add subfolder/subfolder
    By frefry4 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-17-2013, 06:28 PM
  7. Moving an e-mail from a subfolder in Mailbox to the equivalent subfolder in an archive PST
    By johncassell in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2012, 11:31 AM

Tags for this Thread

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