Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Util/IsFileWritable tests
Function:
Required plugins for this example:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/IsFileWritable tests
This example is the version from Sun, 17th Mar 2012.
Project "IsFileWritable tests.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
EventHandler Sub Open() Createfolders TestFolders End EventHandler
Protected Sub CreateFolder(name as string, Permission as integer) dim f as FolderItem = root.Child(name) f.CreateAsFolder folders.Append f dim g as Folderitem = f.Child("testfile") dim t as TextOutputStream = g.CreateTextFile t.Write "Hello World" f.Permissions = Permission End Sub
Protected Sub CreateFolders() dim n as integer root = SpecialFolder.Desktop.Child("test") while root=nil or root.Exists n = n + 1 root = SpecialFolder.Desktop.Child("test"+str(n)) wend root.CreateAsFolder CreateFolder "4 read only", &o444 CreateFolder "2 write only", &o222 CreateFolder "1 execute only", &o111 CreateFolder "6 read+write", &o666 CreateFolder "7 all allowed", &o777 CreateFolder "5 read+execute", &o555 CreateFolder "3 write+execute", &o333 End Sub
Protected Sub TestDelete(f as FolderItem, index as integer) dim g as FolderItem = f.Child("testfile") g.Delete if g.LastErrorCode = 0 then List.Cell(index,5)="works" else List.Cell(index,5)=str(g.LastErrorCode) end if Exception End Sub
Protected Sub TestFolders() for each f as FolderItem in folders test f next End Sub
Protected Sub TestRead(f as FolderItem, index as integer) dim g as FolderItem = f.Child("testfile") dim b as BinaryStream = g.OpenAsBinaryFile(false) if b<>Nil then List.Cell(index,4)="works" else List.Cell(index,4)=str(g.LastErrorCode) end if Exception End Sub
Protected Sub TestWrite(f as FolderItem, index as integer) dim g as FolderItem = f.Child("writetest") dim b as BinaryStream = g.CreateBinaryFile("") if b<>Nil then List.Cell(index,3)="works" else List.Cell(index,3)=str(g.LastErrorCode) end if Exception End Sub
Protected Sub test(f as FolderItem) List.AddRow f.Name List.Cell(List.LastIndex,1)=str(f.IsReadable) List.Cell(List.LastIndex,2)=str(f.IsWriteable) TestWrite f, List.LastIndex TestRead f, List.LastIndex TestDelete f, List.LastIndex Exception // ignore them all End Sub
Property Protected folders() As FolderItem
Property Protected root As FolderItem
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Util Plugin.




Links
MBS Xojo Plugins