Find String

Discussion in 'Software' started by foogoo, Apr 13, 2018.

  1. foogoo

    foogoo Major "foogoo" Geek

    I want to find this text is a txt file and delete that file if the text is found.
    What I have
    findstr /M "Dara la salud" *.txt >new.txt
    for /f %i in (new.txt) do del %i".txt"

    This finds a lot of false positives, what is up?
     
  2. GermanOne

    GermanOne Guest

    Your FINDSTR command is looking for words that contain either Dara, la, or salud. Use the /C: option.
    Code:
    for /f "delims=" %i in ('findstr /MC:"Dara la salud" *.txt') do del "%i"
    Double the percent signs (%i to %%i) if you use this line in a Batch script rather than in the cmd prompt.

    Steffen
     
  3. foogoo

    foogoo Major "foogoo" Geek

    I tried /r /c /m and it still didn't work, if I cut it down to "Dara" it works.
    It finds this file "4.13.2018_9-00-01 AM_1893.txt" but the delete doesn't work.
    New code. removed .txt since it is in the string already.
    The space in the filename is the issue, how do I get that?


    findstr /r /c /M "Dara" *.txt >new.txt

    for /f %%i in (new.txt) do del %%I
     
  4. GermanOne

    GermanOne Guest

    Did you even read my code?

    Already wrong because a colon and the search string needs to follow directly after /c. Option /r is useless in your case.

    Because FOR variables are case-sensitiv. %%I is not the same as %%i. Also as soon as the file name contains spaces it won't work unless you defined "delims=". Also enclose the %%i for the del command in quotes for the same reason.
     
  5. foogoo

    foogoo Major "foogoo" Geek

    The capital I was a paste error - it is not that way in my code. I tried the quotes before I posted and that didn't work.
    for /f %%i in (new.txt) do del "%%i"
     
  6. GermanOne

    GermanOne Guest

    Try
    ... del /f /a "%%i"
    in case your files are read-only or have hidden or system attributes.
     
  7. foogoo

    foogoo Major "foogoo" Geek

    Thanks for the help, I just removed the date from the filename, didn't really need it - could not remove the space. So that fixed it.
     
  8. GermanOne

    GermanOne Guest

    You still didn't read my code and recommendations. To get it runing with spaces you also need "delims="
    Code:
    for /f "delims=" %%i in (new.txt) do del "%%i"
    And since you don't even need the temporary file (because you can process the output of FINDSTR directly) the one line in my first reply would have been sufficient. You only have to double the percent signs as I also already wrote.
    Code:
    for /f "delims=" %%i in ('findstr /MC:"Dara la salud" *.txt') do del "%%i"
     
  9. foogoo

    foogoo Major "foogoo" Geek

    Cool, thanks for the lesson and getting it working.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds