+ Reply to Thread
Results 1 to 15 of 15

List files with some specific text from the folders that also contains specific text

  1. #1
    Registered User
    Join Date
    02-19-2018
    Location
    Czech Republic
    MS-Off Ver
    Excel 2016
    Posts
    68

    List files with some specific text from the folders that also contains specific text

    Hi all,

    Inside the path C:\Users\user\Documents\Test Searcher I have a lot of folders that have the material and the customer name as a part of the folder string name:

    3154- Shoes Puma
    3155- Shirt Puma
    3156- Shoes Adidas
    3157- Belt Nike

    etc...

    Inside these folders then there are still more subfolders with a lot of files. Also note that there are More than 3000 folders....

    My goal was to achieve a Macro to list all the files that the name of the file contains the specific text I would put in A2 through all the subfolders from the main folders that contains part of the text I would put in A1.

    Ex: From all the folders inside the path C:\Users\user\Documents\Test Searcher that for example contains the words "Shoes" to then search inside all the subfolders of that specific folders all the files containing the file name text "template"

    So, in A2 would appear part of the file name "Template" and in A1 part of the folder name "Shoes".

    Because I'm quite a begginer, the closest code I could achieve is the one created by Akatrouble based on this thread https://www.excelforum.com/excel-pro...ple-paths.html I edited the code to achieve the following:

    Based on the folder (and all the subfolders) from the path I put in A1 to look for all the files that contains in the file name the text I put in A2 and make a list to be pasted in the sheet named "Test Searcher"

    Please Login or Register  to view this content.
    Although it is not exactly what I want, I still could work with it. The code works good, but I'm the dealing with a small issue that I certainly don't know how to solve. For some reason the part from this code is case sensitive:

    Please Login or Register  to view this content.
    meaning if I put in range A2 the text "plate" it will list all the files that have the name "Template" for example. But if in A2 I put "PLATE" or "TEMPLATE" it will not list any file if the file name is written as "Template". I've tried to use Lcase function, but because I have some different text possibilites it fails to work in some cases. So my will would be to list all the files without taking into account any capitalization, therefore as a total case insensitive.

    Is there any way to achieve that? Or I should create a completly new code?

    Thanks in advance for your kind attention!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: List files with some specific text from the folders that also contains specific text

    Try:
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    02-19-2018
    Location
    Czech Republic
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: List files with some specific text from the folders that also contains specific text

    Hi TMS, thanks for your fast response.

    As I mentioned, I already tried the function Lcase but the outcome is not the desired one. It really needs to be completely case insensitive!

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: List files with some specific text from the folders that also contains specific text

    This is my old code.
    Wild card serach.

    Enter
    A1:
    *Shoes*

    A2:
    *Template*.xlsx
    or just without file extension like "*Template* for all file types.

    When file dialog appears, select main folder.
    Please Login or Register  to view this content.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: List files with some specific text from the folders that also contains specific text

    Quote Originally Posted by thorblow View Post
    Hi TMS, thanks for your fast response.

    As I mentioned, I already tried the function Lcase but the outcome is not the desired one. It really needs to be completely case insensitive!
    Ah, lots of words. I missed that.

  6. #6
    Registered User
    Join Date
    02-19-2018
    Location
    Czech Republic
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: List files with some specific text from the folders that also contains specific text

    Hi again TMS, I must apologize, your correction it actually worked!

    My statement when I said that Lcase function didn't work, was because I tried like this:

    Please Login or Register  to view this content.
    but with your correction then it works properly as I wanted:

    Please Login or Register  to view this content.
    Anyway, since the new code of jindon appeared, I would rather go for the real macro I would like to have!
    Last edited by thorblow; 06-09-2024 at 04:11 AM.

  7. #7
    Registered User
    Join Date
    02-19-2018
    Location
    Czech Republic
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: List files with some specific text from the folders that also contains specific text

    @jindon

    Hi jindon,

    Your proposal it is actually what Im really looking for! But for some reason it doesn't work it keeps me saying "no file found" when I choose the main folder "C:\Users\user\Documents\Test Searcher" but when I choose the actual subfolder where I know that there are the files, then it works... What might be the problem that doesn't search properly inside the subfolders?

    PS: I edited because at first I thought that it didn't worked at all, but then I realize that it partially worked... Le'ts see if I there is a way to go deep to all the subfolders!
    Last edited by thorblow; 06-09-2024 at 04:20 AM.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: List files with some specific text from the folders that also contains specific text

    Hi again TMS, I must apologize, your correction it actually worked!
    You're welcome. Thanks for the rep.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: List files with some specific text from the folders that also contains specific text

    OOps...
    Can you change
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jindon; 06-09-2024 at 06:23 AM. Reason: Files attached.

  10. #10
    Registered User
    Join Date
    02-19-2018
    Location
    Czech Republic
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: List files with some specific text from the folders that also contains specific text

    @jindon

    Thank you for your fast reply, I don't know if you realized that I just edited my message few minutes ago, so I'm not sure if you took into consideration the previous message...

    Anyway, I have just tried your modifcation it and I keep having the same issue, the macro works properly when I select the path deep in the subfolder that I know that I have the files, but it doesn't work If I choose the main folder that should apply the condition in A1.

    Attachment 871491

    and inside the 3154, etc... folders there are subfolders such as Commercial, Performance, etc... and then inside you can find the files that contains the condition in A2

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: List files with some specific text from the folders that also contains specific text

    Have you tried the attached workbook named GetFiles.xlsm?

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: List files with some specific text from the folders that also contains specific text

    OOps, so sorry, uploaded a wrong file.

    #9 has been edited, so try again....

  13. #13
    Registered User
    Join Date
    02-19-2018
    Location
    Czech Republic
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: List files with some specific text from the folders that also contains specific text

    Hi @jindon,

    Sorry for my late reply, real life is very demanding sometimes :D

    I tried your Excel but the issue is that doesn't go deep enough to more subfolders. In the zip you sent me, try to add more subfolders inside the subfolders and then you will see that the macro fails to work unless you will select the path of the previous folder which contains the file you are looking for...

  14. #14
    Registered User
    Join Date
    02-19-2018
    Location
    Czech Republic
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: List files with some specific text from the folders that also contains specific text

    @jindon,

    With the code I already shared at my first post, is it possible to edited and put there the condition to search into the first folder that contains some specific text? Just saying if it would be faster to find a solution... In the meantime I'm trying by myself if I'm able to achieve it...

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: List files with some specific text from the folders that also contains specific text

    Are you sure?

    It is picking up all the files.

    If the attached doesn't work for you, I will leave this to the others.
    Attached Files Attached Files

+ 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: 3
    Last Post: 05-11-2022, 02:34 PM
  2. [SOLVED] save files to specific folders and creates folders based on month
    By MKLAQ in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-21-2021, 05:11 PM
  3. [SOLVED] [adapt] Import Specific Text - Extracted from Multiple Text Files into Worksheet
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-21-2020, 08:29 AM
  4. List Files (Specific File Type) from Folder & Sub-folders to Excel w/ VBA
    By acerlaptop in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2020, 07:12 AM
  5. Replies: 6
    Last Post: 02-16-2017, 05:08 PM
  6. Replies: 2
    Last Post: 08-05-2013, 07:32 PM
  7. Macro to Parse Text - Import text to Excel from Multiple Text Files & Folders
    By Novice_To_Excel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2012, 01:05 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