How would I go about checking if a file is read-only, and if so change it to be not read-only, and also the other way around?
I'm no DOS expert but if memory serves me, check the "attrib" command. That should tell you what you need to know, and you can use it to set the attributes as well.
attrib -r <filename> make it read/write
attrib +r <filename> make it readonly
This did not work for me until I added a delay. This is my batch script (.bat):
attrib +r %1
ECHO Waiting 1 seconds
PING 1.1.1.1 -n 1 -w 1000 > NUL
%1
ECHO Waiting 3 seconds
PING 1.1.1.1 -n 1 -w 3000 > NUL
attrib -r %1
For bonus points, I wanted to use this to open a certain file type as read-only. So, I right-clicked a file of the time and under "Open With", I chose this batch script. Now I can do that whenever I want to open read-only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With