0

I created a small batch to search for strings in text files and the files that contain this string are moved to a folder created next, at least that's how it should work, does anyone know what it is?

Commands

@echo off

Echo FIND STRING AND MOVE FILES TO FOLDER

Echo.

set /p word=Search for: 
set /p folder=Folder Name: 

md %folder%

FOR /f "tokens=*" %%a IN ('FINDSTR /i /m "%word%" "*.txt"') DO (
IF %ERRORLEVEL% equ 0 MOVE %%a %folder% > Nul

Echo Done!

}

pause

Files to Move to Folder

https://i.stack.imgur.com/lPDuc.png

Thanks!

0

Here's a quick fix for your supplied script:

@Echo Off
Echo FIND STRING AND MOVE FILES TO FOLDER
Echo(

Set/P "word=Search for: "
Set/P "folder=Folder Name: "

If Not Exist "%folder%\" MD "%folder%" 2>Nul||Exit/B

For /F "Delims=" %%A In ('FindStr/ILMC:"%word%" *.txt 2^>Nul'
) Do Move "%%~A" "%folder%">Nul

Echo Done!

Pause

Bear in mind that any script which asks for user input and which doesn't have a relatively robust method in place to protect your system from deliberate or accidental input is potentially dangerous.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.