search for all files by filename but show result as folders

Page 1 of 2 12 LastLast

  1. Posts : 141
    Windows 10
       #1

    search for all files by filename but show result as folders


    I want to search for all files with filename contain word e.g. "web"
    but show the result of those filenames as the containing folder of those files
    so I can move all those folders containing those files..

    e.g.
    file1-web.mp4
    file2-web.mp4

    These files above are in separate folders
    e.g.
    folder1
    folder2


    The problem is windows search in explorer only shows the results as filenames...
    I then need to right click > open file location to be able to move those folders that contain those files..
    If select all those files in results and move them, then the containing folders will remain.

    Is there any way to show the search result as the containing folders of those filenames?
      My Computer


  2. Posts : 42,992
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    Hi, I can suggest a way to go from this:
    search for all files by filename but show result as folders-1.jpg
    - result of search for file, results in two folders to this:
    search for all files by filename but show result as folders-2.jpg

    - where the paths to the containing folders are all found and copied in 2 or 3 clicks.

    1. Install this to add selectable context menu options (free)
    Download Path Copy Copy 19.0

    Accept the defaults.

    2. Perform your search, select all found items, and rt click them.
    Look for and select this option:
    search for all files by filename but show result as folders-untitled.png

    Your clipboard now contains the paths of all found folders.
      My Computers


  3. Posts : 989
    Microsoft Windows 10 Home
       #3

    No good way through the Windows UI.

    But easy enough through PowerShell:


    Code:
    gci *web* -Recurse | select DirectoryName -Unique
    will retrieve the DirectoryNames of every file matching *web* and the -Unique .parameter of Select-Object eliminates duplicate DirectoryNames.

    EDIT: Code below has been fixed.


    You could then move those folders by piping the result to Move-Item:

    Code:
    gci *web* -Recurse | select -expand Directory -Unique | Move-Item -Destination 'C:\web'  -WhatIf
    Remove the -WhatIf if the echoed statements reflect your deisred actions. If the source folders have sub-folders, Move-Item will need the -Recurse parameter as well.
    Last edited by KeithM; 25 Aug 2021 at 01:20.
      My Computer


  4. Posts : 42,992
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #4

    UI method shown in my post.

    Options for that utility for interest:
    search for all files by filename but show result as folders-1.jpg

    search for all files by filename but show result as folders-2.jpg
      My Computers


  5. Posts : 456
    Windows 10
       #5

    You can use robocopy form the command prompt:

    robocopy {Source} {Destination} *web* /s
      My Computer


  6. Posts : 42,992
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #6

    Is that only applicable to a single source folder, or recursively for all subfolders?
    And how long might that take for a large number of files and folders?
      My Computers


  7. Posts : 456
    Windows 10
       #7

    dalchina said:
    Is that only applicable to a single source folder, or recursively for all subfolders?
    And how long might that take for a large number of files and folders?
    Recursively to all sub-folders of the source folder. The copy process takes the normal time it would take for any copy process on Windows it depends on how large and how many files there are and how fast your hard disk is.
      My Computer


  8. Posts : 141
    Windows 10
    Thread Starter
       #8

    dalchina said:
    Hi, I can suggest a way to go from this:
    search for all files by filename but show result as folders-1.jpg
    - result of search for file, results in two folders to this:
    search for all files by filename but show result as folders-2.jpg

    - where the paths to the containing folders are all found and copied in 2 or 3 clicks.

    1. Install this to add selectable context menu options (free)
    Download Path Copy Copy 19.0

    Accept the defaults.

    2. Perform your search, select all found items, and rt click them.
    Look for and select this option:
    search for all files by filename but show result as folders-untitled.png

    Your clipboard now contains the paths of all found folders.
    With all the paths in the clipboard..
    How do you then move all those folders?

    What are the next steps?

    - - - Updated - - -

    ricardobohner said:
    You can use robocopy form the command prompt:

    robocopy {Source} {Destination} *web* /s
    just tested it with some samples
    the command only copies the folders but not move it.
    how would I move those folders?

    - - - Updated - - -

    KeithM said:
    No good way through the Windows UI.

    But easy enough through PowerShell:


    Code:
    gci *web* -Recurse | select DirectoryName -Unique
    will retrieve the DirectoryNames of every file matching *web* and the -Unique .parameter of Select-Object eliminates duplicate DirectoryNames.

    You could then move those folders by piping the result to Move-Item:

    Code:
    gci *.ps1 -Recurse | select DirectoryName -Unique | Move-Item -Destination 'c:\where\ever
    '
    Your second command does not work
    Can you test with some sample and post a sample code that works..

    I tried your second command and it gives error
    e.g.
    Code:
    gci *web* -Recurse | select DirectoryName -Unique > test.ps1
    Code:
     gci test.ps1 -Recurse | select DirectoryName -Unique | Move-Item -Destination 'm:\web'
    also tried this
    Code:
    gci *web* -Recurse | select DirectoryName -Unique | Move-Item -Destination "m:\web"
      My Computer


  9. Posts : 42,992
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #9

    Thank you so much for taking the time to reply.

    How do you then move all those folders?
    But to where would you wish to move them? All to the same folder?
      My Computers


  10. Posts : 989
    Microsoft Windows 10 Home
       #10

    madmax2 said:
    Your second command does not work
    Can you test with some sample and post a sample code that works..

    I tried your second command and it gives error
    e.g.
    Code:
    gci *web* -Recurse | select DirectoryName -Unique > test.ps1
    Code:
     gci test.ps1 -Recurse | select DirectoryName -Unique | Move-Item -Destination 'm:\web'
    also tried this
    Code:
    gci *web* -Recurse | select DirectoryName -Unique | Move-Item -Destination "m:\web"
    Mea culpa! Was posting too late. Code has been fixed in original post as well.

    Code:
    gci *web* -Recurse | select -expand Directory -Unique | Move-Item -Destination 'C:\web'  -WhatIf
    Link to MS documetation for Move-Item added to original as well.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 02:09.
Find Us




Windows 10 Forums