- Code bat
Suicida
: Avoid this!!
at bat:
- for /f %%e in ('findstr "<cd_comiss>P</cd_comiss>" *.*')do del %%e
at the prompt:
- for /f %e in ('findstr "<cd_comiss>P</cd_comiss>" *.*')do del %e
- Deletes all files with string (and without it), even the Bat, did not use filters, any of the characters are worth, and yet, is allowing the action in all files "
*.*
"...
- Obs.: Of course, it would only erase if the code worked, but fortunately it doesn’t, since the command
findstr
and the for
, need characters of escape us: \, /, ^, <, >,< |, &, etc.,.... - Applies also the comma ","
Apaga todos os arquivos com a string, menos o próprio Bat, use filtro:
|findstr /vilc:"%~0"
Ou, Apaga todos os arquivos com a string, menos o próprio Bat, use filtro:
|findstr /vilc:".cmd"
Already with the use of exhaust, from there gets more controlled/filtered this kind of processing, and it will even work, but ends with deleting/listing until a GIF file, file that doesn’t even have the string (complete) searched in its content, but will be deleted because some character of the string will hit!
In this command/code, findstr
is being used to treat all files (*.*
), and how the findstr
tends to treat everything as Regex
(except with the use of /L
, /c:
, \
, I
, etc.. ), so any character of the file that hits ends up being valid...:
- Try not to use unfiltered us commands: del, deltree, rmdir, move, ren, rename, etc...
- Use at all times with a filter more safe/accurate, go through a
echo
before:
- Implement a filtering system to catch a extension specifies: - Example:
"*.xml"
for /f %%e in ('findstr "^<cd_comiss^>P^<\/cd_comiss^>" *.xml^|findstr /vilc:"*\.cmd"')do echo/del %%e
Using a bat
for find and delete files .xml and only those containing the string:
("<cd_comiss>P</cd_comiss>"
):
- Obs.: The string is only in the . xml pair files: 002, 004, 006, 008, 010!
@echo off && setlocal enableextensions enabledelayedexpansion & echo/
echo/ & title <nul & title Q213311 & mode 100,10 & set "_str="\^<\ cd\_comiss\^>P\^<\ \/cd\_comiss\^>"" & echo/
for /f %%c in ('copy /Z "%~dpf0" nul')do set "_cr=%%c" & for /f %%a in ('"prompt $H&for %%b in (0) do rem"')do set "_bs=%%a"
for /f %%f in ('where /r . "*.*"^|findstr /vilc:"%~0"')do for /f ^tokens^=^*delims^=^ %%E in ('type %%f^|findstr /ilm !_str!')do (
ping -n 2 -4 127.0 >nul & echo/ !_cr! & del /q /f "%%~f" >nul && <nul set /p"^=!_bs!!_cr! ^|Arquivo:^| "%%~f" ^| Apagado^!!"
)
It worked! Thanks for your help
– Bueno