Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Dos command to move files that contain a particular word from source to target  (Read 3168 times)

0 Members and 1 Guest are viewing this topic.

Jclams

    Topic Starter


    Newbie

    • Experience: Experienced
    • OS: Windows 10
    I need to move files from source to target folder that contain in the file text a particular word, (not file name)


    Hackoo



      Hopeful
    • Thanked: 42
    • Experience: Expert
    • OS: Windows 10
    Give a try and change for your settings the variables keyWord, SourceFolder, TargetFolder and if you found that correct for your case, just omit the echo command before the command move
    Code: [Select]
    @echo off
    Title Move files that contain a particular word from source to target
    Set "KeyWord=New"
    Set "SourceFolder=%userprofile%\desktop"
    Set "TargetFolder=C:\NewFolder"
    If not exist "%TargetFolder%" MD "%TargetFolder%"
    @for /f "delims=" %%f in ('Dir /b /s "%SourceFolder%\*.txt"') do (
    find /I "%KeyWord%" "%%f" >nul 2>&1 && ( echo move /y "%%f" "%TargetFolder%" )
    )
    pause

    Jclams

      Topic Starter


      Newbie

      • Experience: Experienced
      • OS: Windows 10
      Nicely done, and happy to give it whirl after failing with my archaic attempts. 
      Thank you and will report back.