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
925 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 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 55

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

838 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