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!"
)
)
Moving files containing certain words
Moderator: DosItHelp
Re: Moving files containing certain words
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
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
Try this:
xcopy "c:\folder\*joe*.pst" "d:\destination folder\" /s
xcopy "c:\folder\*joe*.pst" "d:\destination folder\" /s
Re: Moving files containing certain words
foxidrive wrote:Try this:
xcopy "c:\folder\*joe*.pst" "d:\destination folder\" /s
This worked perfect! Thank you!