Solved selective write protection with batch

June 4, 2012 at 11:39:26
Specs: Windows XP
I want to write uprotect a ascii code file if it contains the word 0_MAIN in the first line. Does anybody know hoe to do this with a batch file?

See More: selective write protection with batch

Report •


#1
June 4, 2012 at 19:12:20
✔ Best Answer
If "uprotect" [sic] means unprotect:

:: ===== script starts here ===============
::
:: shc.bat Tue 05-06-2012 9:06:48.32
@echo off & setLocal enableDELAYedeXpansioN

set F=
for /f "tokens=* delims= " %%a in (myfile) do (
echo %%a | find "word" > nul && set F=Y
goto :done
)
:done
if defined F echo attrib -r myfile
goto :eof

::====== script ends here =================


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
June 5, 2012 at 12:17:37
Thx Mechanix!
what if there are multiple folders with multiple files and i want to unprotect all files in the folder with the one containing 0_MAIN.

Report •

#3
June 6, 2012 at 00:06:18
Either put this FOR inside another FOR, or CALL it as a subroutine.


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions


Ask Question