MKDIR issue

Post

Posted
Rating:
#1 (In Topic #206)
Avatar
Administrator
sholzy is in the usergroup ‘unknown’
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

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

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
Gambas One Site Director

To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
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.

Code (gambas)

  1. Public Sub Form_Open()
  2.     If Not Exist(User.Home &/ "Test") Then Mkdir (User.Home &/ "Test")
  3.     If Not Exist(User.Home &/ "Test/Test1") Then Mkdir (User.Home &/ "Test/Test1")

If it worked on older versions of Gambas the bug was there and not in the latest version.

I hope that helps.
Online now: Yes Back to the top

Post

Posted
Rating:
#3
Avatar
Administrator
sholzy is in the usergroup ‘unknown’
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
Gambas One Site Director

To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Online now: No Back to the top
1 guest and 0 members have just viewed this.