1.

Solve : How to combine several conditions in command FOR??

Answer»

Hi everyone,

I would like to combine these two commands as one:

Code: [Select]for /F "usebackq" %%i IN (`net view ^| find /i "BAO-"`) DO set xx=%%i && del /q "%%i\%allusersprofile%\Desktop\*.r2w"
for /F "usebackq" %%i IN (`dir "\\??\c$\Documents and Settings\*.r2w /b /s ^| find /i ".r2w"`) DO set xx=%%i && del /q %%i
Whitout part del /q "%%i\%allusersprofile%\Desktop\*.r2w".

Why do I need:

    locate COMPUTERS on the network with the prefix "BAO-" and all files of type *.R2W in all SUBDIRECTORIES on specified path and delete them. That's all.

Thanks you
I think you are headed in the right direction. Rather than combine them, why not use a subroutine to do the delete. SOMETHING like:
Code: [Select]for /F "usebackq" %%i IN (`net view ^| find /i "BAO-"`) DO call delfiles %%1
goto :EOF

:Delfiles
set compname=%1
del /q "%compname%\%allusersprofile%\Desktop\*.r2w"
goto :EOF

Interesting solution, but it does not solve my problem...

Your syntax is broken

Something like this would be:

Code: [Select]set target="c$\Documents and Settings"
for /F "usebackq" %%i IN (`net view ^| find /i "BAO-"`) DO call delfiles %%1
:delfiles
set compname=%1
for /F "usebackq" %%i IN (`dir "%compname%\%target%\*.r2w" /b /s ^| find /i ".r2w"`) DO set xx=%%i && del /q %%i

Thanks for the reply.for /f "tokens=*" %%a in ('net view^|find/i "BAO-"') do del/q/s "%%a\c$\docume~1\*.r2w"

REM not testedQuote from: Reno on May 07, 2009, 11:11:24 PM
for /f "tokens=*" %%a in ('net view^|find/i "BAO-"') do del/q/s "%%a\c$\docume~1\*.r2w"

REM not tested

Thanks, you helped me - I miss, the command DEL is also the syntax "/s"


Functional and correct syntax should be as follows:
Code: [Select]set prefix=BAO-
set target="c$\Documents and Settings\*.r2w"

for /F "usebackq" %%a IN (`net view ^| find /i "%prefix%"`) DO del /s /q "%%a\%target%"
Caution:

The syntax is not valid for the PC, which runs the script!!

Limited only to networks in the domain. On the local network in the work group also operates, including the PC, which is activated.


That's all folks!


Discussion

No Comment Found