# powershell script to search contents of file and move it to a different folder

I need a script to search the contents of a file and based on the title move to to a different folder - about 10 different possible values/folders. I think it can be done with the switch command but not much of a coder.
Thanks!
###### Who is Participating?

Commented:
It would be enough to copy the title area, retype any confidential data with dummy text.

But as a first try here is my code assuming that the first line of the text files look like:

Title: Analysis
Title: Discounts
Title: Notes

- the first path in line 1 after dir for the source of the reports
- the root of the target folders in line 4 at the end of the move-item line

Of course the pattern should be updated based on the actual title sections.

dir c:\ee\*.txt | Select-String -Pattern "Title:\s(\w+)" -List| %{
$file =$_.path
$target =$_.matches[0].groups[1].value
move-Item -Path $file -Destination "c:\ee\$target"
}

0

Commented:
Could you attach some samples of the text files and specify what kind of values and titles are there!
0

Author Commented:
They are reports so on one of the top several lines have a title such as Analysis, Discounts or Notes so based on what the title is want to move the files to a Analysis folder, etc.  Can't send samples as this is private data.
I got as far as using select-string -pattern "Notes" | copy-item etc but need to go through multiple files and send to different destinations.
Thanks
0

Author Commented:
That doesn't seem to work - there are multiple reports and they aren't consistantly named Title: xxxx -
more like this:
REPORT    - ARB015B   AS OF 02/28/2011                                                                              RUN  03/05/2008
COMPANY   -     3 .                                    ANALYSIS OF ACCOUNTS RECEIVABLE                               PAGE          1
MARKET    -        NOT ON FILE
TERRITORY - 73999  NOT ON FILE

TCO/SUSP  TOTAL     --------------- CURRENT --------  ------------ PAST DUE ----------  ---  NOTES --UA-CASH-
CUSTOMER       CODE  RECEIVABLES  DISCOUNT  NET/NET-30   DATINGS     1 MONTH   2 MONTHS 3 MTH/OVER
-ABLE
--
so I would want to use something like the switch command and select the string pattern and specify where to move the file to.
0

Author Commented:
I got the script to work for me so here are your points - thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.