File Attribute

Mc3762
Member Posts: 26
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" />
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
-
You can do a SHELL command:
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.0 -
Have you tried myfile.WRITEMODE(FALSE); ?0
-
That's only in Navision, I need the file to be read only in the OS. So that you can't open the file from another program.0
-
Thanks :-) But it would be nice with a solution that didn't use the shell feature, because it is not sure that it works in every OS.0
-
Another way to set the file attribute would be to use an automation server to set the file attribute when saving. This also has some limitations but would bypass the use of the SHELL statement.0
-
The FileSystemObject is a powerful tool indeed, and allows many manipulations. You have to use it in a proper way, though, to get the result you want.
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>
John0 -
Thanks 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?0 -
Guess you didn't declare the variable correctly. Are you sure it's set to:
Name DataType Subtype
myFile Automation 'Microsoft Scripting Runtime'.File
Just to be sure, I re-tested the code and here it's running fine.
John0 -
I'm sure that they are set right.
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions