Over time, scripts, tools and other relevant files for application management accumulate on the servers. To prevent accidental removal of such files, I'd normally make these files read-only. Not foolproof ofcourse but enough to prevent most accidents.
To simplify editing scripts I've written a script that will toggle the read-only attribute of any file(s) that is/are dropped on it. The script is Windows only ofcourse.
To simplify editing scripts I've written a script that will toggle the read-only attribute of any file(s) that is/are dropped on it. The script is Windows only ofcourse.
:: Name : Switch_ReadOnly.cmd
:: Purpose: Switches readonly attibute on or off for file(s)
:: Author : P. da Graça
:: Usage : Drop file(s) on this script, it will switch the readonly
:: attribute. Run the script from the commandline to switch all files
:: in the current directory.
::
:: When Who What
:: 08-10-2013 PdaGraca First setup
::
@Echo off
Setlocal
Set File=%*
If Not Defined File Set File=*.*
For %%I IN (%File%) Do Call :ProcessFile %%I
:: Set script itself always to read-only, because you can't drop the script onto itself!
Attrib %0 | find " R " > Nul
If %Errorlevel% NEQ 0 Attrib +r %0
Goto :Eof
:ProcessFile
:: Skip directories
If exist %1\ Goto :Eof
:: Determine if file has readonly attribute
Attrib %1 | find " R " > Nul
Set El=%errorlevel%
If %El% EQU 0 Attrib -r %1
If %El% NEQ 0 Attrib +r %1
Goto :Eof
No comments:
Post a Comment