Check text file for text and move depending on if that text is fou

Discussion in 'Scripting' started by ebferro, May 6, 2008.

  1. ebferro

    ebferro Guest

    I'm a newbie when it comes to PowerShell but I think it will do what I want
    it to do. I just need some help getting started. I would like to look at
    the files in a directory l:\mdr2000 and if they are of a certain type with an
    extension .000, examine the contents of those files for the text 'M-460-2'.
    The files with the .000 extension are text files. If they contain the text
    'M-460-2', I'd like to move the file to a directory v:\cas\a2000. If the
    text is not present, I'd like to move the file to another directory
    l:\mdr2000\tested. Could someone help me with some code to do this? Thanks
    in advance for the help.
    ebferro, May 6, 2008
    1. Advertisements

  2. I don't know how to do it with PowerShell but here is a batch file
    @echo off
    setlocal enabledelayedexpansion
    set string=M-460-2
    set source=l:\mdr2000
    set target1=v:\cas\a2000
    set target2=l:\mdr2000\tested
    if not exist "%target1%" md "%target1%"
    if not exist "%target2%" md "%target2%"
    for %%a in ("%source%\*.000") do (
    set target=%target2%
    find /i "%string%" "%%a" > nul && set target=%target1%
    echo move "%%a" "!target!"

    Remove the word "echo" in the line with the "move" command
    to activate the batch file.
    Pegasus \(MVP\), May 6, 2008
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.