Unable to create subfolder in mkdir under Documents folder in iOS

Asked 2 years ago, Updated 2 years ago, 95 views

/var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX/Documents
I wanted to create a subfolder, so I wrote the following source code.
I created a subfolder with mkdir, but the mkdir return value is -1, and it fails.


in https://developer.apple.com/jp/documentation/FileSystemProgrammingGuide.pdf According to page 15, you should be able to create a subfolder, but somehow it fails.


in baseDirectory of arguments /var/mobile/Applications/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX/Documents passed and failed.
When I passed /var/mobile/Applications/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/Library/Caches, the return value of mkdir was =0, and I checked with an app called Iexproler and found the folder configuration, so I think there is no problem with the processing itself.

From the following source, baseDirectory contains /var/mobile/Applications/XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXXXXXX/Documents, and assetDirectory has passed a subfolder to create like a/b/c/d/e.

■ I use NSLog for debugging, but eventually delete it and it becomes a cpp file.

//Include file being used
# include<sys/stat.h>
# include <dient.h>
# include <string> 
// Declare to use template
using namespace std;

//****************************************
// directory creation process
//****************************************
void MakeDirectoryFunction(string baseDirectory, string assetDirectory)
{
    intretint = 0;
    int startPos = 0;
    intendPos=assetDirectory.find("/", startPos);

    US>//#stringCut=";
    string makeString=baseDirectory;

    while(endPos>0){
        NSLog(@"start=%d", startPos);
        NSLog(@"end=%d", endPos);
        stringCut=assetDirectory.substr(startPos, endPos-startPos);
        NSLog(@"stringCut=%s", stringCut.c_str());
        makeString=makeString+"/"+stringCut;
        NSLog(@"makeString=%s", makeString.c_str());

        retint = mkdir(makeString.c_str(),0777);
        NSLog(@"retint=%d", retint);
        startPos = endPos+1;
        endPos=assetDirectory.find("/", startPos);
    }
}

iOS: 8.3 xCode: 6.3.2

06/20 Additional note: Unity Application.persistentDataPath has been passed to iOS.

ios c++ unity3d c

2022-09-30 20:48

1 Answers

/var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX/Documents
I wrote the following source code to create a subfolder.

In iPhone 5s+iOS 8.3, I checked the path in the Documents folder and found the path below.

/var/mobile/Containers/Data/Application/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX/Documents

This is not an answer, but I will provide it as one piece of information.

Also, use the code below to retrieve the path of the Documents folder.

//#import<Foundation/Foundation.h>

NSAray* pathArray= NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSSstring* path=pathArray[0];


2022-09-30 20:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.