Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 961
  • Last Modified:

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

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
Mohammed Hamada
Asked:
Mohammed Hamada
  • 4
1 Solution
 
oBdACommented:
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
 
Julian HansenCommented:
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
 
Mohammed HamadaSenior IT ConsultantAuthor Commented:
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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
Mohammed HamadaSenior IT ConsultantAuthor Commented:
No it worked, actually the folder path was just misspelled! I have fixed it and it worked perfectly right.

Thanks a lot
0
 
Mohammed HamadaSenior IT ConsultantAuthor Commented:
OPppps, sorry I assigned the points to the wrong person, I have requested moderators attention to re-assign points to  oBdA.

Thanks
0
 
Mohammed HamadaSenior IT ConsultantAuthor Commented:
thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now