PDA

View Full Version : Function to set ReadOnly to false



Worm
03-04-2004, 03:07 PM
This is a function to set the ReadOnly attribute to false on all files in folder and it's subfolder. Useful when you've copied files from a CD to the hard drive.

Sample Call
UndoReadOnly("C:\Program Files\My App")


Global Function


function UndoReadOnly(sFolder)
local n;
local m_File;

--find all files in the passed folder
m_tblFiles = File.Find(sFolder, "*.*", true, true, nil)

if m_tblFiles ~= nil then
--setup the attribute table
attrib = {};
attrib.ReadOnly = false;
--enumerate table
for n, m_File in m_tblFiles do
--set attribute
File.SetAttributes(m_File, attrib);
end
end

--clean up
attrib = nil;
m_tblFiles = nil;
end

yosik
03-05-2004, 05:31 AM
Thanks Worm. It can be very useful.
There is also a small *.bat program that does that.
Problem is that sometimes, you want/need some of the files to be read only and some not (example, backing up a project in Video Editing on some systems).
I personally always zip the files/folders before burning them on CD. That way their attrib remain.
If you zip the files/folders, you remain at the original states for all you files.
Yossi

TJ_Tigger
03-05-2004, 06:09 AM
Originally posted by yosik

Problem is that sometimes, you want/need some of the files to be read only and some not (example, backing up a project in Video Editing on some systems).


Thats a good idea. You could add another parameter that could be passed to the function as a table where in the table would contain a list of files that you want to remain in the readonly state.

tROFiles = {"File1.ext", "File2.ext", "File3.ext", "File4.ext"}
UndoReadOnly("C:\Program Files\My App", tROFiles)

davels
11-16-2007, 11:23 AM
Thx, nice function ;)