Batch File looping until certain text is displayedHow can I pass arguments to a batch file?Batch file to delete files older than N daysSplit long commands in multiple lines through batch fileHow can I echo a newline in a batch file?Windows batch files: .bat vs .cmd?Looping through the content of a file in BashHow to sleep for 5 seconds in a batch file/cmd?What is the current directory in a batch file?Batch File: Running if else command and regedit add together in one fileBatch FOR loop processing drops equal and comma characters

What if a revenant (monster) gains fire resistance?

Pre-mixing cryogenic fuels and using only one fuel tank

Why can Carol Danvers change her suit colours in the first place?

User Story breakdown - Technical Task + User Feature

Can I still be respawned if I die by falling off the map?

Open a doc from terminal, but not by its name

Calculating total slots

Why does a simple loop result in ASYNC_NETWORK_IO waits?

How can I avoid dust and bubbles when installing window film?

Why "had" in "[something] we would have made had we used [something]"?

What should you do if you miss a job interview (deliberately)?

putting logo on same line but after title, latex

Lowest total scrabble score

Why Shazam when there is already Superman?

Add big quotation marks inside my colorbox

Mixing PEX brands

Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?

Is there a RAID 0 Equivalent for RAM?

What to do when eye contact makes your subordinate uncomfortable?

Does malloc reserve more space while allocating memory?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

The IT department bottlenecks progress, how should I handle this?

Does the UK parliament need to pass secondary legislation to accept the Article 50 extension

What is the highest possible scrabble score for placing a single tile



Batch File looping until certain text is displayed


How can I pass arguments to a batch file?Batch file to delete files older than N daysSplit long commands in multiple lines through batch fileHow can I echo a newline in a batch file?Windows batch files: .bat vs .cmd?Looping through the content of a file in BashHow to sleep for 5 seconds in a batch file/cmd?What is the current directory in a batch file?Batch File: Running if else command and regedit add together in one fileBatch FOR loop processing drops equal and comma characters













1















Currently have a batch file for replacing NTFS permissions using the takeown and icacls commands, i have added these commands to a loop and it works great.



Is there a way to exit the loop when a certain response is displayed? like "Failed processing 0 files" or something like that? the code i am using is below, hopefully this will help some other people also.



@echo off
setlocal enabledelayedexpansion
for /l %%x in (1,1,1000) do (

echo Taking ownsership of Folders & Files - loop %%x
for /f "delims=" %%i in ('takeown.exe /R /A /F "F:SharesNetBackup Clients" /D N ^| findstr /i /C:"Failed processing 0 files"') do (
set "error=%%i"
if "!errorlevel!"=="0" goto :end
)

echo Applying permissions to filestore - loop %%x
icacls.exe "F:SharesNetBackup Clients" /grant "DomainGroup":F /grant "DomainGroup":R /T /C

echo Finished applying permissions to filestore - loop %%x >> C:Loopy.txt
)
goto :eof
:end
echo %error%


Many Thanks










share|improve this question









New contributor




Mark Mckie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2





    Check the condition with an if and goto :label outside the for (code block)

    – LotPings
    yesterday















1















Currently have a batch file for replacing NTFS permissions using the takeown and icacls commands, i have added these commands to a loop and it works great.



Is there a way to exit the loop when a certain response is displayed? like "Failed processing 0 files" or something like that? the code i am using is below, hopefully this will help some other people also.



@echo off
setlocal enabledelayedexpansion
for /l %%x in (1,1,1000) do (

echo Taking ownsership of Folders & Files - loop %%x
for /f "delims=" %%i in ('takeown.exe /R /A /F "F:SharesNetBackup Clients" /D N ^| findstr /i /C:"Failed processing 0 files"') do (
set "error=%%i"
if "!errorlevel!"=="0" goto :end
)

echo Applying permissions to filestore - loop %%x
icacls.exe "F:SharesNetBackup Clients" /grant "DomainGroup":F /grant "DomainGroup":R /T /C

echo Finished applying permissions to filestore - loop %%x >> C:Loopy.txt
)
goto :eof
:end
echo %error%


Many Thanks










share|improve this question









New contributor




Mark Mckie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2





    Check the condition with an if and goto :label outside the for (code block)

    – LotPings
    yesterday













1












1








1








Currently have a batch file for replacing NTFS permissions using the takeown and icacls commands, i have added these commands to a loop and it works great.



Is there a way to exit the loop when a certain response is displayed? like "Failed processing 0 files" or something like that? the code i am using is below, hopefully this will help some other people also.



@echo off
setlocal enabledelayedexpansion
for /l %%x in (1,1,1000) do (

echo Taking ownsership of Folders & Files - loop %%x
for /f "delims=" %%i in ('takeown.exe /R /A /F "F:SharesNetBackup Clients" /D N ^| findstr /i /C:"Failed processing 0 files"') do (
set "error=%%i"
if "!errorlevel!"=="0" goto :end
)

echo Applying permissions to filestore - loop %%x
icacls.exe "F:SharesNetBackup Clients" /grant "DomainGroup":F /grant "DomainGroup":R /T /C

echo Finished applying permissions to filestore - loop %%x >> C:Loopy.txt
)
goto :eof
:end
echo %error%


Many Thanks










share|improve this question









New contributor




Mark Mckie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












Currently have a batch file for replacing NTFS permissions using the takeown and icacls commands, i have added these commands to a loop and it works great.



Is there a way to exit the loop when a certain response is displayed? like "Failed processing 0 files" or something like that? the code i am using is below, hopefully this will help some other people also.



@echo off
setlocal enabledelayedexpansion
for /l %%x in (1,1,1000) do (

echo Taking ownsership of Folders & Files - loop %%x
for /f "delims=" %%i in ('takeown.exe /R /A /F "F:SharesNetBackup Clients" /D N ^| findstr /i /C:"Failed processing 0 files"') do (
set "error=%%i"
if "!errorlevel!"=="0" goto :end
)

echo Applying permissions to filestore - loop %%x
icacls.exe "F:SharesNetBackup Clients" /grant "DomainGroup":F /grant "DomainGroup":R /T /C

echo Finished applying permissions to filestore - loop %%x >> C:Loopy.txt
)
goto :eof
:end
echo %error%


Many Thanks







loops batch-file icacls






share|improve this question









New contributor




Mark Mckie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Mark Mckie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday







Mark Mckie













New contributor




Mark Mckie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Mark MckieMark Mckie

84




84




New contributor




Mark Mckie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Mark Mckie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Mark Mckie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 2





    Check the condition with an if and goto :label outside the for (code block)

    – LotPings
    yesterday












  • 2





    Check the condition with an if and goto :label outside the for (code block)

    – LotPings
    yesterday







2




2





Check the condition with an if and goto :label outside the for (code block)

– LotPings
yesterday





Check the condition with an if and goto :label outside the for (code block)

– LotPings
yesterday












1 Answer
1






active

oldest

votes


















1














I think you might have the error the wrong way around, so you would need to adjust it accordingly, but we use findstr and if we meet the requirement (errorlevel is 0) we exit the loop.



@echo off
setlocal enabledelayedexpansion
for /l %%x in (1,1,1000) do (
echo %%x
for /f "delims=" %%i in ('takeown.exe /R /A /F "\fileservershare" /D N ^| findstr /i "Failed processing 0 files"') do (
set "error=%%i"
if "!errorlevel!"=="0" goto :end
)
echo Finished takeown >> C:Loopy.txt
icacls.exe "\fileservershare" /grant "DomainGroup":F /grant "DomainGroup":R /T /C
echo Finished icacls >> C:Loopy.txt
echo Loop %%x >> C:Loopy.txt
)
goto :eof
:end
echo %error%





share|improve this answer

























  • Yes thank you for this, the takeown command should be in the inside loop! but this is great! thanks very much! really helped.

    – Mark Mckie
    yesterday











  • the takedown command is in the first loop.

    – Gerhard Barnard
    yesterday












  • Sorry i may have confused things, the takeown command produces the text that the loop needs to exit from. after there are "Failed processing 0 files" then i will run a icacls command one last time manually. So it goes takeown -> icacls -> takeown -> icacls -> takeown etc until the text is displayed from the takeown command. sorry

    – Mark Mckie
    yesterday











  • then just replace the icacls command string in the loop with the takedown process.. i.e for /f "delims=" %%i in ('takedown...)...

    – Gerhard Barnard
    yesterday











  • edited answer to demonstrate what I mean.. you would need to modify and test as I cannot replicate the environment.

    – Gerhard Barnard
    yesterday










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Mark Mckie is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280565%2fbatch-file-looping-until-certain-text-is-displayed%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I think you might have the error the wrong way around, so you would need to adjust it accordingly, but we use findstr and if we meet the requirement (errorlevel is 0) we exit the loop.



@echo off
setlocal enabledelayedexpansion
for /l %%x in (1,1,1000) do (
echo %%x
for /f "delims=" %%i in ('takeown.exe /R /A /F "\fileservershare" /D N ^| findstr /i "Failed processing 0 files"') do (
set "error=%%i"
if "!errorlevel!"=="0" goto :end
)
echo Finished takeown >> C:Loopy.txt
icacls.exe "\fileservershare" /grant "DomainGroup":F /grant "DomainGroup":R /T /C
echo Finished icacls >> C:Loopy.txt
echo Loop %%x >> C:Loopy.txt
)
goto :eof
:end
echo %error%





share|improve this answer

























  • Yes thank you for this, the takeown command should be in the inside loop! but this is great! thanks very much! really helped.

    – Mark Mckie
    yesterday











  • the takedown command is in the first loop.

    – Gerhard Barnard
    yesterday












  • Sorry i may have confused things, the takeown command produces the text that the loop needs to exit from. after there are "Failed processing 0 files" then i will run a icacls command one last time manually. So it goes takeown -> icacls -> takeown -> icacls -> takeown etc until the text is displayed from the takeown command. sorry

    – Mark Mckie
    yesterday











  • then just replace the icacls command string in the loop with the takedown process.. i.e for /f "delims=" %%i in ('takedown...)...

    – Gerhard Barnard
    yesterday











  • edited answer to demonstrate what I mean.. you would need to modify and test as I cannot replicate the environment.

    – Gerhard Barnard
    yesterday















1














I think you might have the error the wrong way around, so you would need to adjust it accordingly, but we use findstr and if we meet the requirement (errorlevel is 0) we exit the loop.



@echo off
setlocal enabledelayedexpansion
for /l %%x in (1,1,1000) do (
echo %%x
for /f "delims=" %%i in ('takeown.exe /R /A /F "\fileservershare" /D N ^| findstr /i "Failed processing 0 files"') do (
set "error=%%i"
if "!errorlevel!"=="0" goto :end
)
echo Finished takeown >> C:Loopy.txt
icacls.exe "\fileservershare" /grant "DomainGroup":F /grant "DomainGroup":R /T /C
echo Finished icacls >> C:Loopy.txt
echo Loop %%x >> C:Loopy.txt
)
goto :eof
:end
echo %error%





share|improve this answer

























  • Yes thank you for this, the takeown command should be in the inside loop! but this is great! thanks very much! really helped.

    – Mark Mckie
    yesterday











  • the takedown command is in the first loop.

    – Gerhard Barnard
    yesterday












  • Sorry i may have confused things, the takeown command produces the text that the loop needs to exit from. after there are "Failed processing 0 files" then i will run a icacls command one last time manually. So it goes takeown -> icacls -> takeown -> icacls -> takeown etc until the text is displayed from the takeown command. sorry

    – Mark Mckie
    yesterday











  • then just replace the icacls command string in the loop with the takedown process.. i.e for /f "delims=" %%i in ('takedown...)...

    – Gerhard Barnard
    yesterday











  • edited answer to demonstrate what I mean.. you would need to modify and test as I cannot replicate the environment.

    – Gerhard Barnard
    yesterday













1












1








1







I think you might have the error the wrong way around, so you would need to adjust it accordingly, but we use findstr and if we meet the requirement (errorlevel is 0) we exit the loop.



@echo off
setlocal enabledelayedexpansion
for /l %%x in (1,1,1000) do (
echo %%x
for /f "delims=" %%i in ('takeown.exe /R /A /F "\fileservershare" /D N ^| findstr /i "Failed processing 0 files"') do (
set "error=%%i"
if "!errorlevel!"=="0" goto :end
)
echo Finished takeown >> C:Loopy.txt
icacls.exe "\fileservershare" /grant "DomainGroup":F /grant "DomainGroup":R /T /C
echo Finished icacls >> C:Loopy.txt
echo Loop %%x >> C:Loopy.txt
)
goto :eof
:end
echo %error%





share|improve this answer















I think you might have the error the wrong way around, so you would need to adjust it accordingly, but we use findstr and if we meet the requirement (errorlevel is 0) we exit the loop.



@echo off
setlocal enabledelayedexpansion
for /l %%x in (1,1,1000) do (
echo %%x
for /f "delims=" %%i in ('takeown.exe /R /A /F "\fileservershare" /D N ^| findstr /i "Failed processing 0 files"') do (
set "error=%%i"
if "!errorlevel!"=="0" goto :end
)
echo Finished takeown >> C:Loopy.txt
icacls.exe "\fileservershare" /grant "DomainGroup":F /grant "DomainGroup":R /T /C
echo Finished icacls >> C:Loopy.txt
echo Loop %%x >> C:Loopy.txt
)
goto :eof
:end
echo %error%






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









Gerhard BarnardGerhard Barnard

9,03631233




9,03631233












  • Yes thank you for this, the takeown command should be in the inside loop! but this is great! thanks very much! really helped.

    – Mark Mckie
    yesterday











  • the takedown command is in the first loop.

    – Gerhard Barnard
    yesterday












  • Sorry i may have confused things, the takeown command produces the text that the loop needs to exit from. after there are "Failed processing 0 files" then i will run a icacls command one last time manually. So it goes takeown -> icacls -> takeown -> icacls -> takeown etc until the text is displayed from the takeown command. sorry

    – Mark Mckie
    yesterday











  • then just replace the icacls command string in the loop with the takedown process.. i.e for /f "delims=" %%i in ('takedown...)...

    – Gerhard Barnard
    yesterday











  • edited answer to demonstrate what I mean.. you would need to modify and test as I cannot replicate the environment.

    – Gerhard Barnard
    yesterday

















  • Yes thank you for this, the takeown command should be in the inside loop! but this is great! thanks very much! really helped.

    – Mark Mckie
    yesterday











  • the takedown command is in the first loop.

    – Gerhard Barnard
    yesterday












  • Sorry i may have confused things, the takeown command produces the text that the loop needs to exit from. after there are "Failed processing 0 files" then i will run a icacls command one last time manually. So it goes takeown -> icacls -> takeown -> icacls -> takeown etc until the text is displayed from the takeown command. sorry

    – Mark Mckie
    yesterday











  • then just replace the icacls command string in the loop with the takedown process.. i.e for /f "delims=" %%i in ('takedown...)...

    – Gerhard Barnard
    yesterday











  • edited answer to demonstrate what I mean.. you would need to modify and test as I cannot replicate the environment.

    – Gerhard Barnard
    yesterday
















Yes thank you for this, the takeown command should be in the inside loop! but this is great! thanks very much! really helped.

– Mark Mckie
yesterday





Yes thank you for this, the takeown command should be in the inside loop! but this is great! thanks very much! really helped.

– Mark Mckie
yesterday













the takedown command is in the first loop.

– Gerhard Barnard
yesterday






the takedown command is in the first loop.

– Gerhard Barnard
yesterday














Sorry i may have confused things, the takeown command produces the text that the loop needs to exit from. after there are "Failed processing 0 files" then i will run a icacls command one last time manually. So it goes takeown -> icacls -> takeown -> icacls -> takeown etc until the text is displayed from the takeown command. sorry

– Mark Mckie
yesterday





Sorry i may have confused things, the takeown command produces the text that the loop needs to exit from. after there are "Failed processing 0 files" then i will run a icacls command one last time manually. So it goes takeown -> icacls -> takeown -> icacls -> takeown etc until the text is displayed from the takeown command. sorry

– Mark Mckie
yesterday













then just replace the icacls command string in the loop with the takedown process.. i.e for /f "delims=" %%i in ('takedown...)...

– Gerhard Barnard
yesterday





then just replace the icacls command string in the loop with the takedown process.. i.e for /f "delims=" %%i in ('takedown...)...

– Gerhard Barnard
yesterday













edited answer to demonstrate what I mean.. you would need to modify and test as I cannot replicate the environment.

– Gerhard Barnard
yesterday





edited answer to demonstrate what I mean.. you would need to modify and test as I cannot replicate the environment.

– Gerhard Barnard
yesterday












Mark Mckie is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















Mark Mckie is a new contributor. Be nice, and check out our Code of Conduct.












Mark Mckie is a new contributor. Be nice, and check out our Code of Conduct.











Mark Mckie is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280565%2fbatch-file-looping-until-certain-text-is-displayed%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해