Page 1 of 1

Moving files containing certain words

Posted: 04 Aug 2013 11:02
by podgodd
I am in need of a batch script that will move files containing certain words from one folder to another, all while keeping the same folder structure. From what I gather online, I have found the following script and it does not seem to be working. Any help would be greatly appreciated!

@echo off
setlocal enabledelayedexpansion

set SOURCE_DIR=C:\Source
set DEST_DIR=C:\Destination
set FILENAMES_TO_COPY=data.zip info.txt

for /R "%SOURCE_DIR%" %%F IN (%FILENAMES_TO_COPY%) do (
if exist "%%F" (
set FILE_DIR=%%~dpF
set FILE_INTERMEDIATE_DIR=!FILE_DIR:%SOURCE_DIR%=!
xcopy /E /I /Y "%%F" "%DEST_DIR%!FILE_INTERMEDIATE_DIR!"
)
)

Re: Moving files containing certain words

Posted: 04 Aug 2013 11:06
by aGerman
Do you mean certain words in the files contents? In that case: What file types (extensions) are you talking about?

Re: Moving files containing certain words

Posted: 04 Aug 2013 11:17
by podgodd
Yes, certain words in the filetypes themselves. Say all files containing the word 'joe' need to be copied to a new location while keeping the same directory. All file types have a .pst extensions. Thanks in advance!

Re: Moving files containing certain words

Posted: 04 Aug 2013 11:42
by foxidrive
Try this:

xcopy "c:\folder\*joe*.pst" "d:\destination folder\" /s

Re: Moving files containing certain words

Posted: 04 Aug 2013 16:35
by podgodd
foxidrive wrote:Try this:

xcopy "c:\folder\*joe*.pst" "d:\destination folder\" /s



This worked perfect! Thank you!