Solved

Batch file to check certain word in a folder full of files (Reports) and copy them to a different folder on the network

Posted on 2014-01-13
7
938 Views
Last Modified: 2014-01-14
Hello Experts

I need a batch file that would check for the word (HP) in a folder full of daily reports, the batch would check inside of every file if there's a word HP . if its found, the batch will copy the file to a different folder that's publicly shared on the network.

This should happen on daily basis.

The folder path if requested is (C:\1-WebServices-1\DeviceUpdateLogs\Server\Audit\imageUpdates)

The Public folder is c:\PublicFolder.

Would appreciate your help.

Thanks
0
Comment
Question by:Mohammed Hamada
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39776510
Try this batch script; it's currently in test mode and will only display the copy commands it would normally run, so that you can test it.
Remove the uppercase ECHO in line 11 to run it for real.
@echo off
setlocal
set SourcePath=C:\1-WebServices-1\DeviceUpdateLogs\Server\Audit\imageUpdates
set TargetPath=C:\PublicFolder
set FileMask=*.*
set Search=HP
for %%a in ("%SourcePath%\%FileMask%") do (
	echo Processing %%~nxa ...
	findstr.exe /r "\<%Search%\>" "%%a" >NUL
	if not errorlevel 1 (
		ECHO copy "%%a" "%TargetPath%"
	)
)
echo Done.

Open in new window

0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 39776528
Question - is HP unique enough to distinguish files?
Can this appear anywhere in the file or only a specific location?

For instance one file could contain

HP Deskjet

And another could contain

index.php

Both will match on the HP part but might not yield the required results.
0
 
LVL 24

Author Comment

by:Mohammed Hamada
ID: 39776548
Hi oBdA

I have tried it but it didn't work. I copy it to notepad and removed the ECHO in line 11 then saved as copy.bat on desktop
run it as administrator... but nothing happened.

I should mention maybe that i'm on Windows 2012! could that affect the batch file? even though no errors were reported. I didn't get anything.
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 24

Author Comment

by:Mohammed Hamada
ID: 39776555
No it worked, actually the folder path was just misspelled! I have fixed it and it worked perfectly right.

Thanks a lot
0
 
LVL 24

Author Comment

by:Mohammed Hamada
ID: 39776564
OPppps, sorry I assigned the points to the wrong person, I have requested moderators attention to re-assign points to  oBdA.

Thanks
0
 
LVL 24

Author Closing Comment

by:Mohammed Hamada
ID: 39776786
thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question