How to make my program to understand that it's incorrect?

I want to loop my program to create a folder in Dropbox. Once it successed, to get out of loop. For example, if "fld0", "fld1", "fld2" exist, make fld3 and get out of loop. But the problem is that my program thinks that it created a folder "fld0" successfully, even if "fld0" was created before. In my code I can actually change json.UpdateBool("autorename", false); to true. But I want to have a variable equal to "fld%d" of successfully created the new folder (if "fld0", "fld1", "fld2" exist, get equality of "fld3"). How it can be done?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "pch.h"
#include <iostream>
#include <fstream>
#include<istream>
#include<string>
#include <Windows.h>
#include <tchar.h>
#include <CkRest.h>
#include <CkJsonObject.h>
#include <CkStream.h>
#include <CkDateTime.h>
#include <CkDtObj.h>
#include <CkGlobal.h>
#include <CkRest.h>
#include <CkJsonObject.h>
#include <CkStringBuilder.h>
#include <CkCrypt2.h>

using namespace std;



void ChilkatSample(void)
{
    // The Chilkat API can be unlocked for a fully-functional 30-day trial by passing any
    // string to the UnlockBundle method.  A program can unlock once at the start. Once unlocked,
    // all subsequently instantiated objects are created in the unlocked state. 
    // 
    // After licensing Chilkat, replace the "Anything for 30-day trial" with the purchased unlock code.
    // To verify the purchased unlock code was recognized, examine the contents of the LastErrorText
    // property after unlocking.  For example:
    CkGlobal glob;
    bool success = glob.UnlockBundle("");
    if (success != true) {
        std::cout << glob.lastErrorText() << "\r\n";
        return;
    }

    int status = glob.get_UnlockStatus();
    if (status == 2) {
        std::cout << "Unlocked using purchased unlock code." << "\r\n";
    }
    else {
        std::cout << "Unlocked in trial mode." << "\r\n";
    }

    // The LastErrorText can be examined in the success case to see if it was unlocked in
    // trial more, or with a purchased unlock code.
    std::cout << glob.lastErrorText() << "\r\n";
}

void ChilkatSample0(void)
{

    CkRest rest;
    bool success;

    //  URL: https://api.dropboxapi.com/2/files/create_folder_v2
    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    success = rest.Connect("api.dropboxapi.com", port, bTls, bAutoReconnect);
    if (success != true) {
        std::cout << "ConnectFailReason: " << rest.get_ConnectFailReason() << "\r\n";
        std::cout << rest.lastErrorText() << "\r\n";
        //return;
    }

    //  See the Online Tool for Generating JSON Creation Code
    CkJsonObject json;

    int i = 0;
    char folder[100];
    for (;;)
    {
        sprintf(folder, "/fld%d", i++);

        json.UpdateString("path", folder);
        json.UpdateBool("autorename", false);

        rest.AddHeader("Authorization", "Bearer access_token");
        rest.AddHeader("Content-Type", "application/json");

        CkStringBuilder sbRequestBody;
        json.EmitSb(sbRequestBody);
        CkStringBuilder sbResponseBody;
        success = rest.FullRequestSb("POST", "/2/files/create_folder_v2", sbRequestBody, sbResponseBody);

        if (success == true) {
            std::cout << rest.lastErrorText() << "\r\n";
            return;
    }
    }


int main()
{
    ChilkatSample();
    ChilkatSample0();
}


Maybe check if a folder exists before trying to create it?
https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder

Dropbox has many communities, are you signed up on any of them?
I mean, that's where you'll find the highest concentration of people who are familiar with that API.
Topic archived. No new replies allowed.