I need to move some XML files from one directory to another based on whether a particular string is present in it or not(i.e. if the string is present then move, else keep it). Is it possible to do so using a batch script?
2 Answers
Use FINDSTR like this to move file fred if it contains the word "hello":
findstr hello fred
if %ERRORLEVEL% == 0 (
echo Move that puppy
)
If you want to search insensitive to case (lowercase vs uppercase) use FINDSTR /I
Powershell is not available on all Windows versions, by the way, whereas this is.
2 Comments
user3481013
Thanks for the answer. I am using windows server 2003. Powershell is most probably unavailable here.
Mark Setchell
Ok, so hopefully this is the correct way to go for you (as this is not Powershell).
This should copy the files with string in the filename.
@echo off
for /f "delims=" %%a in ('dir *.xml /b /a-d ^|find /i "string" ') do copy "%%a" "d:\new\folder"