search for all files by filename but show result as folders

Page 2 of 2 FirstFirst 12

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

    Once you have a txt file with your list of folders you can use this idea:
    Copying Folders and Files From A List in Command Prompt | Chris Tierney

    (which I've not tried).

    The GUI method gives you a list very quickly which you can review.
      My Computers


  2. Posts : 456
    Windows 10
       #12

    To move instead of copying:

    robocopy {source} {destination} /move /e
      My Computer


  3. Posts : 141
    Windows 10
    Thread Starter
       #13

    KeithM said:
    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.
    The command works but how to prevent it finding the word "web" in non video files (jpg and any other file types)?

    e.g.
    *web*.jpg

    I want to find the word web in all possible video files (e.g. mkv, mp4, avi, etc...)

    - - - Updated - - -

    ricardobohner said:
    To move instead of copying:

    robocopy {source} {destination} /move /e
    Thanks.
    Tested and this works but the downside is it takes quite a long time due to it needing to copy first to destination and then delete the original source.
    Powershell method actually moves the folders without copying so it is much faster.
      My Computer


  4. Posts : 989
    Microsoft Windows 10 Home
       #14

    madmax2 said:
    The command works but how to prevent it finding the word "web" in non video files (jpg and any other file types)?

    e.g.
    *web*.jpg

    I want to find the word web in all possible video files (e.g. mkv, mp4, avi, etc...)
    ...

    Powershell method actually moves the folders without copying so it is much faster.
    You didn't give detaailed info on the folder structure, but be aware you asked to move any folder that contains one or more target files. So if an undesired file is in the same folder as a target file, it will be moved, because we're moving entire folders, not individual files.

    If you want the folders with only targeted files, that's a little more code. But at this point, I'll assume that wanted vs. unwanted files are always in separate folders.

    There are a number of ways to filter the files, but for the average stand-alone user, the differences in processing for that are most likely minimal.

    Working with the previous command, one way would be to create an array of strings containing the desired extensioins. The most straightforward way would be:

    Code:
    $TargetExt = @( '.mkv' , '.mp4' , '.avi' )
    But, if you plan to re-use code, for ease of editing and eradability, I like using a Here-String and then using the -Split operator to split the string on the newline character to create the array:
    Code:
    $TargetExt = @'
    .mkv
    .mp4
    .avi
    '@ -split '\n'
    WIth that, we can filter the output of Get-ChidItem (gci) using Where-Object (where) to check if the Extension property of the FileInfo object before piping it to Move-Item:

    Code:
    $TargetExt = @'
    .mkv
    .mp4
    .avi
    '@ -split '\n'
    
    gci *web* -Recurse | where Extension -in $TargetExt | select -expand Directory -Unique | Move-Item -Destination 'C:\web'  -WhatIf
    Last edited by KeithM; 31 Aug 2021 at 11:16.
      My Computer


  5. Posts : 141
    Windows 10
    Thread Starter
       #15

    KeithM said:
    You didn't give detaailed info on the folder structure, but be aware you asked to move any folder that contains one or more target files. So if an undesired file is in the same folder as a target file, it will be moved, because we're moving entire folders, not individual files.

    If you want the folders with only targeted files, that's a little more code. But at this point, I'll assume that wanted vs. unwanted files are always in separate folders.

    There are a number of ways to filter the files, but for the average stand-alone user, the differences in processing for that are most likely minimal.

    Working with the previous command, one way would be to create an array of strings containing the desired extensioins. The most straightforward way would be:

    Code:
    $TargetExt = @( '.mkv' , '.mp4' , '.avi' )
    But, if you plan to re-use code, for ease of editing and eradability, I like using a Here-String and then using the -Split operator to split the string on the newline character to create the array:
    Code:
    $TargetExt = @'
    .mkv
    .mp4
    .avi
    ' -split '\n'
    WIth that, we can filter the output of Get-ChidItem (gci) using Where-Object (where) to check if the Extension property of the FileInfo object before piping it to Move-Item:

    Code:
    $TargetExt = @'
    .mkv
    .mp4
    .avi
    ' -split '\n'
    
    gci *web* -Recurse | where Extension -in $TargetExt | select -expand Directory -Unique | Move-Item -Destination 'C:\web'  -WhatIf
    The first code works
    $TargetExt =@('.mkv','.mp4','.avi')

    but when I tested the second method using the split operator it does not work.

    Can you test it?

    Code:
    $TargetExt = @'
    .mkv
    .mp4
    .avi
    '-split '\n'
    Last edited by madmax2; 31 Aug 2021 at 09:47.
      My Computer


  6. Posts : 989
    Microsoft Windows 10 Home
       #16

    madmax2 said:
    The first code works
    $TargetExt =@('.mkv','.mp4','.avi')

    but when I tested the second method using the split operator it does not work.

    Can you test it?

    Code:
    $TargetExt = @'
    .mkv
    .mp4
    .avi
    '-split '\n'
    Lost an @ while cutting & pasting --- cursor jumps around in these editors at hight zoom levels and can't always find where it went or what it did while I was looking down at the keyboard.

    <WaggingFinger>That being said, had you followed the documentation link for the Here-String included in the reply as well, you would have figured it out for yourself! </WaggingFinger>
      My Computer


  7. Posts : 141
    Windows 10
    Thread Starter
       #17

    KeithM said:
    Lost an @ while cutting & pasting --- cursor jumps around in these editors at hight zoom levels and can't always find where it went or what it did while I was looking down at the keyboard.

    <WaggingFinger>That being said, had you followed the documentation link for the Here-String included in the reply as well, you would have figured it out for yourself! </WaggingFinger>
    What do you mean you lost an @ ?
    where else should the @ symbol go in this code with the split operator?

    Code:
     
    $TargetExt = @'
    .mkv
    .mp4
    .avi
    '-split '\n'
    
    gci *web*-Recurse|whereExtension-in $TargetExt |select-expand Directory-Unique|Move-Item-Destination'C:\web'-WhatIf
    In regards to that link you posted, Move-Item https://docs.microsoft.com/en-us/pow...powershell-7.1
    it didn't have any examples about using the -split operator that you added.

    Also what I want to do here is a lot more complex/harder (ie search for a term, only of some filetypes and only showing the folders of those files) than the simple example provided in that link so I would not have figured it out myself anyway since I am quite a noob in regards to powershell scripting/coding..
    So it is good that you were able to help with this problem.
      My Computer


  8. Posts : 989
    Microsoft Windows 10 Home
       #18

    madmax2 said:
    What do you mean you lost an @ ?
    where else should the @ symbol go in this code with the split operator?
    To complete the closing quote of the Here-String. I edited the code in my original reply... :
    Code:
     
    $TargetExt = @'
    .mkv
    .mp4
    .avi
    '@ -split '\n'
    
    gci *web*-Recurse|whereExtension-in $TargetExt |select-expand Directory-Unique|Move-Item-Destination'C:\web'-WhatIf



    In regards to that link you posted, Move-Item https://docs.microsoft.com/en-us/pow...powershell-7.1
    it didn't have any examples about using the -split operator that you added.
    In #14, there are links to MS documentation for Here-String, -Split operator, and Where-Object.
      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 10:37.
Find Us




Windows 10 Forums