Allowing permission on a directory programaticaly

Just starting out? Need help? Post your questions and find answers here.
loulou2522
Enthusiast
Enthusiast
Posts: 557
Joined: Tue Oct 14, 2014 12:09 pm

Allowing permission on a directory programaticaly

Post by loulou2522 »

Is-it possible with purebasic to allow read and write and read permission on a directory ?
Thanks in advance
infratec
Always Here
Always Here
Posts: 7714
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Allowing permission on a directory programaticaly

Post by infratec »

On Linux :?:

chmod_()

For such a question more informations are needed.
loulou2522
Enthusiast
Enthusiast
Posts: 557
Joined: Tue Oct 14, 2014 12:09 pm

Re: Allowing permission on a directory programaticaly

Post 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
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Allowing permission on a directory programaticaly

Post 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:
infratec
Always Here
Always Here
Posts: 7714
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Allowing permission on a directory programaticaly

Post by infratec »

My hint was not enough :wink:

From which OS are you talking???
Bo Marchais
User
User
Posts: 61
Joined: Sun Apr 03, 2016 12:03 am

Re: Allowing permission on a directory programaticaly

Post 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!
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Allowing permission on a directory programaticaly

Post 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.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Allowing permission on a directory programaticaly

Post 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:
Post Reply