Thanks marcov, your code works like a charm...
Something else... Can you convert this simple code to Lazarus? please.
(Yes, I already know we can do this through Lazarus directly. I just want to see the convertion from .vbs.)
This code is to see if a file is read-only and, if it is not, marks it as read-only.
Best regards.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\MyFolder\TextFile.txt")
If objFile.Attributes = objFile.Attributes AND 1 Then
objFile.Attributes = objFile.Attributes XOR 1
End If
You do realize that I figured most of this out while writing the first reply? It is just simple substitutions (paying attention to case, since this one of the few cases where Pascal is case sensitive), and looking up properties in MSDN.
I'm by no means a COM expert. Note that errorhandling will probably also be more complex
{$mode delphi}
uses windows,variants,sysutils,activex,comobj;
var
objFSO,
objFile :OLeVariant;
attr : integer;
begin
objFSO := CreateOleObject('Scripting.FileSystemObject');
objFile := objFSO.GetFile('C:\repo\ul.txt');
attr:=objFile.Attributes;
writeln('Attributes: ',attr);
if (attr and 1)=0 then
objfile.Attributes:=attr xor 1;
end.
Inbetween I also wrote an iterator (something I hinted on in comment in the last example)
A for loop now looks like
var
objlist,
obj : Olevariant;
listiter : oEnumIterator;
for obj in listiter.Enumerate(objlist) do // or e.g. objlist.Properties_ if you want to list properties.
writeln(Obj.Version);
I attach the last example rewritten in that way. I also tried to do something with the date object in the last list based on some code on MSDN