We help IT Professionals succeed at work.

Script to search for all files in a file

598 Views
Last Modified: 2008-01-09
Hi,

I have a file which has the Ntloginnames.What i want is a way to search thesde names in a particular folder and move them to the specified folder.

I have ntloginnam.pst such file say 1000 in a folder.
In the txt file i just have the ntloginname.So need a way to search the ntlogin.pst files in the folder and move all files found.

Regards
Sharath
Comment
Watch Question

Commented:
Do you still need an answer for this? Do you mind using Powershell?

Author

Commented:
No problem until i can run it on Windows....

I need this badly...
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
BSonPosh:
I get this. Am i doing some thing wrong.If i need to search for exe,txt files what should i change

PS C:\Documents and Settings\sharathr> $folder = "C:\Pstools"
PS C:\Documents and Settings\sharathr> $PutHere = "C:\Pstools1"
PS C:\Documents and Settings\sharathr> $users = get-content "c:\filename.txt"
PS C:\Documents and Settings\sharathr> $files = get-childitem $folder *.pst
PS C:\Documents and Settings\sharathr> foreach($user in $users)
>> foreach($user in $users)
>> {
>>    $files | ?{$_.Name -match $user} | %{move-item $_.fullname -dest "$puthere\$($_.Name)" -whatif}
>> }
>>
Missing statement body in foreach loop.
At line:2 char:1
+ f <<<< oreach($user in $users)

Commented:
$users is suppose to be file with the list of users.... is FileName.txt a realy file? The problem is when it tries to get the file it gets nothing returned I suspect.

As for the other file types you can change
$files = get-childitem $folder *.pst
do what ever ext you want, or if you want all but not folders then this
$files = get-childitem $folder | ?{!($_.PSIsContainer)}

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.