MKDIR issue

Post your Gambas programming questions here.
Post Reply
User avatar
Got2BeFree
Posts: 91
Joined: Saturday 26th November 2016 2:52am
Location: Lost

MKDIR issue

Post by Got2BeFree »

Has something changed in the past few Gambas releases? I used to be able to create a nested directory structure to store app data. The last app I created was 2 about years ago (using Gambas 3.8.x) and it worked fine. I've recently updated to 3.11.4 on both my openSUSE and Debian boxes and I'm finding MKDIR isn't working like it used to on either box.

I can create the first level directory, but when trying to create a directory inside I get an "access forbidden" error.

Testing code:

Code: Select all

Public Sub Form_Open()
    If Not Exist(User.Home &/ "Test") Then Mkdir (User.Home &/ "Test")
    If Not Exist("Test/Test1") Then Mkdir ("Test/Test1")
End
This is the actual block of code used in many of my apps that worked without issue:

Code: Select all

Public Sub CheckDirIntegrity()
    If Not Exist(User.Home &/ Mglobal.sBaseDir) Then Mkdir (User.Home &/ Mglobal.sBaseDir)      ' check for base directory
    If Not Exist(Mglobal.sAppDirPath) Then Mkdir (Mglobal.sAppDirPath)          ' check for application directory
    If Not Exist(Mglobal.sConfigPath) Then Mkdir (Mglobal.sConfigPath)         ' check for configuration directory
    If Not Exist(Mglobal.sDataPath) Then Mkdir (Mglobal.sDataPath)              ' check for data directory
End
sholzy

I'm wondering around lost in the past, not knowing where the present is.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: MKDIR issue

Post by cogier »

Your code is failing as you are trying to create a folder at root:-
Line 1 refers to /home/<name>/Test
Line 2 refers to /Test/Test1 - You need root access to create this, hence the error.

Your first line is correct but your second line also needs the 'User.Home &/'. The code below works.
Public Sub Form_Open()
    If Not Exist(User.Home &/ "Test") Then Mkdir (User.Home &/ "Test")
    If Not Exist(User.Home &/ "Test/Test1") Then Mkdir (User.Home &/ "Test/Test1")
End
If it worked on older versions of Gambas the bug was there and not in the latest version.

I hope that helps.
User avatar
Got2BeFree
Posts: 91
Joined: Saturday 26th November 2016 2:52am
Location: Lost

Re: MKDIR issue

Post by Got2BeFree »

Thanks, cogier, for your reply.

I figured out what was wrong:
1. working on code after coming home from 12 hours of work on too little sleep and being awake almost 16 hours :shock:
2. remembering differently what code I thought I copied and what I actually copied
3. updating Gambas in the middle of coding
4. trying to debug during [1.] above thinking [3.] above was the issue
5. posting "test" code that wasn't fully representative of my actual code

Your answer didn't make much sense to me since I knew my code had "User.Home" as part of the path string, so I started comparing old code to new code. After about 10 minutes of staring at code I realized that when copying old code to the new app, I didn't copy all the code. :oops:
sholzy

I'm wondering around lost in the past, not knowing where the present is.
Post Reply