Page 1 of 1

Allowing permission on a directory programaticaly

Posted: Thu Apr 14, 2016 12:41 pm
by loulou2522
Is-it possible with purebasic to allow read and write and read permission on a directory ?
Thanks in advance

Re: Allowing permission on a directory programaticaly

Posted: Thu Apr 14, 2016 2:07 pm
by infratec
On Linux :?:

chmod_()

For such a question more informations are needed.

Re: Allowing permission on a directory programaticaly

Posted: Thu Apr 14, 2016 5:19 pm
by loulou2522
In fact my question is the flollowing
I install a programm in a directory on which a write prefs Files and sqlite database.
I want to test if te directory is read only and if so i want to give permission to write files on these directory.
Is it suffisant like information or you need more and what kind of information
THanks in advance

Re: Allowing permission on a directory programaticaly

Posted: Thu Apr 14, 2016 5:48 pm
by Marc56us
Test write permission with CreateFile()

Code: Select all

TestFile.s = "C:\Test_Remove.txt"

If CreateFile(0, TestFile)                           ; = If CreateFile(0, TestFile) <> 0
    Debug "I'm happy, I can write here :-)"
    DeleteFile(TestFile)                             ; Remove test file
Else
    Debug "Sorry, I can't write here file :-("
EndIf
But the best way to store user data is to create a new sub dir in user home dir
See GetHomeDirectory()

:wink:

Re: Allowing permission on a directory programaticaly

Posted: Thu Apr 14, 2016 5:56 pm
by infratec
My hint was not enough :wink:

From which OS are you talking???

Re: Allowing permission on a directory programaticaly

Posted: Thu Apr 14, 2016 7:51 pm
by Bo Marchais
A long time ago I started building diagnostics into my installers and often on programs as well.

These diagnostics explain permission errors and things like that. I found out that clients will often accept something printed on a screen blaming the environment, but quickly dispute the situation when a support person explains it, especially if the support person is young or uncertain.

It costs money to troubleshoot or argue...and it causes negative feelings. All of my newer software does this in a very pretty and "web2.0" way with lots of graphics and suggestions. Naturally, these are handed over to the IT guy, who then can't shrug and blame the software (to get out of working) for the problem... Very nice!

It's easy to write a procedure to do the following on arbitrary paths:
1) verify path to dir is valid
2) write a junk file (or fail)
3) *modify* the junk file - by any method you like
4) read from the junk file to see if change occurred
5) copy the file to junkfile2/rename it
6) delete junkfile2 after testing to see if it's there
7) delete junk file
8) look at dir and make sure they're gone.
---------------------------
You can add checking for free disk space if you like. Sometimes the amount of space shown is NOT what's actually available, so I've had times where I've had to write out a file larger than the real data, then delete it and write out the real file. You probably won't run into that, but my clients are often pathological at best. I love them dearly, but I won't trust their infrastructure!

Re: Allowing permission on a directory programaticaly

Posted: Fri Apr 15, 2016 8:35 am
by Danilo
loulou2522 wrote:Is-it possible with purebasic to allow read and write and read permission on a directory ?
- GetFileAttributes(Filename$)
- SetFileAttributes(Filename$, Attributes)

Code: Select all

Filename$  |  The name of the file to modify. This can also specify the name of a directory.
You may need administrator privileges to modify some file/directory attributes.

Re: Allowing permission on a directory programaticaly

Posted: Fri Apr 15, 2016 8:49 am
by Marc56us
loulou2522 wrote:In fact my question is the flollowing
I install a programm in a directory on which a write prefs Files and sqlite database.
I want to test if te directory is read only and if so i want to give permission to write files on these directory.
Also, (and before) don't forget to test if directory is directory or file and/or exist
Use FileSize()

Returns the size of the file in bytes, or one of the following values:

-1: File not found.
-2: File is a directory.

:wink: