Path := 'C:\test.txt';
Create(myFile);
Create(myFilesystemobject);
myFile := muFileSystemObject.getfile(Path);
myFile.attributes := myFile.attributes + 1;
This does not work?
I Need to set a file to be read only. myFileSystemObject is a microsoft scripting runtime object, named Filesystemobject.
MyFile is also a Microsft scripting runtime object, named File.
Please help
Thanks in advance.
Morti
<img border="0" title="" alt="" src="images/smiles/icon_confused.gif" />
0
Comments
attrib FILENAME +r
This will set the file to read only from dos. Because you're using dos, though, there are limitations with file name length.
Hope this helps.
This gives a better result:
Vars:
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code:</font><HR><pre>
Name DataType Subtype Length
myFileSystemObject Automation 'Microsoft Scripting Runtime'.FileSystemObject
myFile Automation 'Microsoft Scripting Runtime'.File
myPath Text 200
myAttributes Integer
</pre><HR></BLOCKQUOTE>
Code:
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code:</font><HR><pre>CREATE(myFileSystemObject);
myPath := 'c:\test.txt';
myFileSystemObject.GetFile(myPath);
myFile := myFileSystemObject.GetFile(myPath);
myAttributes := myFile.Attributes;
IF (myAttributes MOD 2 <> 0) THEN
MESSAGE('File %1 is now ReadOnly',myPath)
ELSE
MESSAGE('File %1 is now Read/Write',myPath);
IF (myAttributes MOD 2 <> 0) THEN
myAttributes := myAttributes - 1 //Normal
ELSE
myAttributes := myAttributes + 1; //ReadOnly
myFile.Attributes := FORMAT(myAttributes);
IF (myAttributes MOD 2 <> 0) THEN
MESSAGE('File %1 is now ReadOnly',myPath)
ELSE
MESSAGE('File %1 is now Read/Write',myPath); </pre><HR></BLOCKQUOTE>
John
But I get some errors.
The first 4 lines is ok, but as soon as I use the myFile.Attributes, it says that it is not a legal data type.
Why is this?
Name DataType Subtype
myFile Automation 'Microsoft Scripting Runtime'.File
Just to be sure, I re-tested the code and here it's running fine.
John
It could be because of our financial is ver. 2.01B
Where we cant make the automation variables. But we do have a word codeunit with these variables in, so what I do is I copy this unit, and changes the variable names, and objects.