Computing.Net > Forums > Office Software > Batch file to apply read only attr.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file to apply read only attr.

Reply to Message Icon

Name: Thomy
Date: October 21, 2009 at 02:29:09 Pacific
OS: Windows
Subcategory: General
Comment:

Hello.
In order not to mess with older files (by opening them and accidentally saving), I change their attribute to read only. This can be done by right clicking a folder and selecting the read only box.
I was wondering if this can be done more easily (since I often forget doing it). I was thinking about a batch file that adds the read only feature to all the files in a folder (including sub folders) older than a month (or x days), if they do not already have it.
Can this be done?

Thanks in advance!



Sponsored Link
Ads by Google

Response Number 1
Name: Fist (by fmwap)
Date: October 21, 2009 at 02:38:24 Pacific
Reply:

attrib +R * /S

would make everything in the current tree read only

With GNU find you could probably get this down to one command, something like:

find / -atime +4w -exec attrib +R {} \S ;

Should set +R on anything that hasn't been accessed in more than 4 weeks.


1

Response Number 2
Name: Thomy
Date: October 21, 2009 at 03:17:22 Pacific
Reply:

Thank you for your quick reply. I suppose it should be something simple like that.
But help me just a little bit more. Where do I find this "GNU find" program? I've searched a bit around and as far as I’ve seen this is Unix software... I’m using Windows.
Thanks!


0

Response Number 3
Name: Mike (by mmcconaghy)
Date: October 21, 2009 at 04:51:18 Pacific
Reply:

Look here:

http://www.openetwork.com/berk.html

The Berkeley Find does not have -atime, but it does have -mtime, there is a difference between the two, one being that -mtime does not recognize weeks,.

Also, since there is already a find command in Windows, you should probably make a separate directory called Unix and put all your Unix commands there. Then when you need to use the Unix commands simply use the complete path.

So something like:

c:\path\to\unix\find / -mtime +30 -exec attrib +R {} \S ;

You also might want to ask your question in the Programming Forum. There is probably a DOS batch way of doing this.

MIKE

http://www.skeptic.com/


1

Response Number 4
Name: Thomy
Date: October 21, 2009 at 05:43:11 Pacific
Reply:

I am almost there :-)...
Using Berkeley find the batch works, but I still have 2 problems:
find . -mtime +45 -exec attrib {} +r ;
This command works only if the filename does not have spaces within... and I don't know how to solve this.
Second, I would like find to check first if the attribute R is already present, since the folder is quite big and this would probably speed up the process.

P.S. I am not familiar with the Programming Forum, but I am already getting a lot of help here. Thanks!


0

Response Number 5
Name: Thomy
Date: October 21, 2009 at 06:06:24 Pacific
Reply:

P.S.
Even "{}" does not work.


0

Related Posts

See More



Response Number 6
Name: Fist (by fmwap)
Date: October 21, 2009 at 21:46:40 Pacific
Reply:

Sorry, GNU Find has been ported to Windows w/ cygwin - I should have been clearer about that.

My 4.1 version has the same problem you describe, but the new 4.2.20 version escapes spaces in filenames correctly.

Try grabbing the new version at:
http://gnuwin32.sourceforge.net/pac...

(Note the part about the 'setup' utility and required DLL's)


1

Response Number 7
Name: Thomy
Date: October 22, 2009 at 00:09:07 Pacific
Reply:

Thanks Fist, now it works. Thanks!
Anyhow, this find program is quite versatile. I’ve tried to analyze the help file but it is far from plain English. The thing I would like to add is a test to verify if the attribute is already present. This is because now it takes 4 minutes to perform the task on a intranet folder, but if it would be quicker I would use it also on another - larger folder.
Can you help me?


0

Response Number 8
Name: Fist (by fmwap)
Date: October 22, 2009 at 00:44:05 Pacific
Reply:

Add this:

-perm 444

(That's POSIX permissions in Octal - see: http://en.wikipedia.org/wiki/File_s... )


0

Response Number 9
Name: Fist (by fmwap)
Date: October 22, 2009 at 00:50:48 Pacific
Reply:

Wait, I"m wrong

The above finds files that are already read only

Use this to find files that are writable

-perm +2


1

Response Number 10
Name: Thomy
Date: October 22, 2009 at 01:03:29 Pacific
Reply:

Well... that’s it! It’s done.
I was hoping to gain more speed with this additional filter, but it is just 30-45 seconds quicker. Still a good improvement.
Thank you all for the help. I was not aware that this technology is so versatile. Good invention this “internet”! :-)

Again, great! Thanks!


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Batch file to apply read only attr.

batch file to refresh RAM www.computing.net/answers/office/batch-file-to-refresh-ram-/8562.html

Random Word read-only/all users www.computing.net/answers/office/random-word-readonlyall-users/2898.html

where's the read only message? www.computing.net/answers/office/wheres-the-read-only-message/6897.html