mkdir not detecting if directory exist

on the first pass it detect if directory exist
when it go true the routing again it doesnt
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
    #include "stdafx.h"
    #include "Plugin.h"
    #include "sample.h"
    #include <bitset>
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    #include <direct.h>
    #include<windows.h>
    using namespace std;
    char t5d[100]="\0";
    char temp[100]="\0";
    char stringdata[256]="";
    char fixmem[256]="";
    char group[256]=""; 
    char t5c[256]="";

    c3 = 0;
    tprice = (close[c4] * .05) + close[c4];
    strcat(t5d, "D:\\output\\");
    mkdir(t5d);
    snprintf(temp, 7, "%f", date1.array[c4]);
    strcat(t5d, temp);
    strcat(t5d, "\\");
    mkdir(t5d);
    strcat(t5d, ticker.string);
    strcat(t5d, "_");
    snprintf(temp, 6, "%f", close[c4]);
    strcat(t5d, temp);
    strcat(t5d, "_");
    snprintf(temp, 6, "%f", tprice);
    strcat(t5d, temp);
    mkdir(t5d);
    strcat(t5d, "\\");
    strcat(t5d, "Group_");
    strcat(t5d, group);
    mkdir(t5d);
    strcat(t5d, group1);
    mkdir(t5d);
    c1 = -1;
    while (c1 == -1)
      {
       strcpy(t5c, t5d);
       sprintf(temp, "%d", c3);
       strcat(t5c, temp);
       c1 = _mkdir(t5c);
       c3++;
      }
      strcat(t5c,"\\7zip.7z");


it get stuck in the loop.
after the first pass
the first pass when c3=0 is ok
then it go thru my code
and wont create directory #1

the debugger shows the string ok

Line 46 calls _mkdir() instead of mkdir(). What's the difference?

You can probable get the system to tell you exactly why mkdir failed by printing the value of errno afterwards:

1
2
3
4
5
6
#include <cerrno>
...
c1= mkdir(t5c);
if (c1) {
    cout << "mkdir("<<t5c <<") failed: " strerror(errno) << '\n';
}

strcat(t5d, "D:\\output\\"); should be strcpy
I never cleard t5d

dumb mistake
Last edited on
Registered users can post here. Sign in or register to post.