Lock files inside a app. package

Is there a good way to lock a file?
So basically as long the app is running and you try to remove that file, you get a warning it is still open for reading/writing

This doesn’t work:

Dim sourceFile As Folderitem
Dim t As TextInputStream
sourceFile = SpecialFolder.Preferences.child("lockfile.txt")
t=TextInputStream.Open(sourceFile)

I do not close the Textinputstream with t.close to make sure it stays open.

But still you can delete the file without OSX complaining it is busy.

Any way to make OSX complaining the file is still being read/written to?

The thread title is wrong… should ‘How to lock files’ :slight_smile:

you might try this via SHELL… but I advise caution

To lock or unlock a file in terminal, use chflags command. To lock, use

chflags uchg filename

and to unlock, use

chflags nouchg filename

Thanks Dave. Works perfect !