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
900 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
  • 4
7 Comments
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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 51

Expert Comment

by:Julian Hansen
Comment Utility
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 23

Author Comment

by:Mohammed Hamada
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 23

Author Comment

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

Thanks a lot
0
 
LVL 23

Author Comment

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

Thanks
0
 
LVL 23

Author Closing Comment

by:Mohammed Hamada
Comment Utility
thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now