[?]: WinCC Flexible Script Code for "Get file attributes"

ProTool, WinCC flexible, WinCC, PP/OP/TP/TD/MP
Homeroid_BL
Posts: 258
Joined: Fri Apr 03, 2009 3:24 pm
Location: Bosnia and Herzegovina

[?]: WinCC Flexible Script Code for "Get file attributes"

Post by Homeroid_BL »

Hi all!

Can someone write here a code (for script in WinCC Flex),
so I can see if my file eg. "c:\Logs\Log_1.csv" is "ReadOnly" or not?
Thanks!
Lepes9
Posts: 17
Joined: Fri Sep 24, 2010 10:03 pm

Re: [?]: WinCC Flexible Script Code for "Get file attributes

Post by Lepes9 »

Try this:

Code: Select all

On Error Resume Next
Dim FSO, File, szFolder, szFileName, iAttrib
szFolder = "C:\Temp\"
szFileName = "ExampleFile.txt"
Set FSO = CreateObject("Scripting.FileSystemObject")
If Err.Number <> 0 Then
	ShowSystemAlarm Err.Description
	Err.Clear
	Exit Sub
End If
Set File = FSO.GetFile(szFolder & szFileName)
SmartTags("Attrib") = File.Attributes
If Err.Number <> 0 Then
	ShowSystemAlarm Err.Description
	Err.Clear
	Exit Sub
End If
Set File = Nothing
Set FSO = Nothing
You can use a tag ("Attrib" in my script) or an internal variable to save the attributes if the file.

The return values of Attributes-property are:
0: Normal (file without attributes)
1: ReadOnly
2: Hidden
4: System
16: Directory (not a file)
32: Archive
1024: Alias (it's a shortcut)
2048: Compressed
If the return value is 7 than it is hidden, system file for reading only (1+2+4)

Have fun!
(Scripting makes fun.)

Greets

PS: Did you try F1? ;-)
Homeroid_BL
Posts: 258
Joined: Fri Apr 03, 2009 3:24 pm
Location: Bosnia and Herzegovina

Re: [?]: WinCC Flexible Script Code for "Get file attributes

Post by Homeroid_BL »

Thanks, Lepes9!
F1 gives no help for it. You will see that they use Object.SetAttr i Object.GetAttr which is not usable, even you didn't use it.

Thanks again! :)
Lepes9
Posts: 17
Joined: Fri Sep 24, 2010 10:03 pm

Re: [?]: WinCC Flexible Script Code for "Get file attributes

Post by Lepes9 »

Hi Homeroid_BL!

If you want to change the attributes of a file you have to assign a value to the file.
E.g.:

Code: Select all

File.Attributes = 33
Now the file is an archive (NOT compressed!) and read-only.

Greetings