I'm writing a batch file and I need to know if a file is read only. How can I do that ?
I know how to get them using the %~a modifier but I don't know what to do with this output. It gives something like -ra------. How can I parse this in batch file ?
To test a specific file:
To get a list of read only files
To get a list of read/write files
To list all files and report whether read only or read/write:
EDIT
Patrick's answer fails if the file name contains
!
. This can be solved by toggling delayed expansion on and off within the loop, but there is another way to probe the%%~aF
value without resorting to delayed expansion, or even an environment variable:Something like this should work:
When I run this I get the following output: