Moving files containing certain words

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
podgodd
Posts: 10
Joined: 14 Jan 2013 14:15

Moving files containing certain words

#1 Post by podgodd » 04 Aug 2013 11:02

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!"
)
)

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Moving files containing certain words

#2 Post by aGerman » 04 Aug 2013 11:06

Do you mean certain words in the files contents? In that case: What file types (extensions) are you talking about?

podgodd
Posts: 10
Joined: 14 Jan 2013 14:15

Re: Moving files containing certain words

#3 Post by podgodd » 04 Aug 2013 11:17

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!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Moving files containing certain words

#4 Post by foxidrive » 04 Aug 2013 11:42

Try this:

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

podgodd
Posts: 10
Joined: 14 Jan 2013 14:15

Re: Moving files containing certain words

#5 Post by podgodd » 04 Aug 2013 16:35

foxidrive wrote:Try this:

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



This worked perfect! Thank you!

Post Reply