Solved Batch file, Find a word part of the file name and move

February 2, 2018 at 04:44:47
Specs: Windows 7
I'm looking fo a Command line, Batch file or VB, to do the followings;

1-Find the word "World" in part of the file name regardless of extension, and move it to c:\Dir3
for example, I have a file in these locations,
c:\dir1\Good Morning World.txt
c:\dir2\We Love USA.avi
c:\dir3\
c:\dir4\

2-Find the word "USA" in part of the file name regardless of extension, and move it to c:\Dir4


See More: Batch file, Find a word part of the file name and move

Report •

#1
February 2, 2018 at 06:08:56
✔ Best Answer
You can do something like this in batch script :
@echo off
Title Find Word in file name and move it 
set "Dir1=C:\Dir1\"
set "Dir2=C:\Dir2\"
set "Dir3=C:\Dir3\"
set "Dir4=C:\Dir4\"
set "Word1=World"
set "Word2=USA"
for /f "delims=" %%a in ('Dir /s /b "%Dir1%" ^| find /I "%Word1%"') do ( echo found "%%a" && Move "%%a" "%Dir3%" )
for /f "delims=" %%b in ('Dir /s /b "%Dir2%" ^| find /I "%Word2%"') do ( echo found "%%b" && Move "%%b" "%Dir4%" )
pause


Report •

#2
February 3, 2018 at 09:00:27
Worked great thank you!

Report •

#3
February 4, 2018 at 05:21:03
Nice ! so don't forget to accept it as an answer or mark it as solved thread
Have a nice day dude !
Hackoo ;)

message edited by Hackoo


Report •

Related Solutions

#4
February 8, 2018 at 08:17:10
i guess he forgot, fixed that

i5-6600K[delid]@4.814GHz/4.613GHz cache@1.38v | 2x4GB Crucial-DDR4-2133@14-14-14-28 1T 2808MHz@1.37v
ASUS Z170K
Samsung 250GB SSD 850 EVO
MSI Armor RX 570 4GB@1380c/2087m BiosMod
VS450


Report •

Ask Question