• Advertisement
Sign in to follow this  

mkdir

This topic is 3462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

weird problem. i have a createFolder func that creates every folder one by one to the full path. for example "/opt/here/new fold/last/file.txt" would create opt if needed and work its way up to last. Right now, it last is missing and everything up to exist. when i mkdir i get the error EEXIST as expected. When it finally gets to last i get ENOENT, WTF!?! man 2 mkdir says [ENOENT] A component of the path prefix does not exist or path is an empty string. everything before last exist, so... wtf?! i tried using both /opt/here/new fold/last and /opt/here/new fold/last/ both get me that error. Whats going on?

Share this post


Link to post
Share on other sites
Advertisement
I'm guessing you're using a recursive function... Could you post your code? Maybe you're traversing the list of folders to create backwards?

Share this post


Link to post
Share on other sites
Nope, i have a fake mkdir for win32 and it works perfectly there.

I was using a fake mkdir that takes in 1 param (used for windows). I just realized it called mkdir(sz, 0), so maybe 0 is causing the problem?

PS: how do i find the error variable when i get the error value? i dont like doing what i did below.


size_t fs_createSubs(const char*sz)
{
std::string s = sz, s2;
size_t pos=3;
while (1)
{
size_t a, b, c;
a = s.find("\\", pos);
b = s.find("/", pos);
c = min(a, b);
if (c == -1u)
break;

pos = c+1;
s2 = s.substr(0, c);
// s2 += "/";
if (mkdir(s2.c_str(), 0))
{
int a=errno, b;
if (a == EEXIST)
printf("%d\n", b);
b++;
if (a == EACCES)
printf("%d\n", b);
b++;
if (a == EFAULT)
printf("%d\n", b);
b++;
if (a == ELOOP)
printf("%d\n", b);
b++;
if (a == ENAMETOOLONG)
printf("%d\n", b);
b++;
if (a == ENOENT)
printf("%d\n", b);
b++;
if (a == ENOMEM)
printf("%d\n", b);
b++;
if (a == ENOSPC)
printf("%d\n", b);
b++;
if (a == ENOTDIR)
printf("%d\n", b);
b++;
if (a == EPERM)
printf("%d\n", b);
b++;
if (a == EROFS)
printf("%d\n", b);
b++;
}
}
return 0;
}


Share this post


Link to post
Share on other sites
what should i use as the 2nd param of mkdir? i tried googling but didnt find anything that wasnt php or cmd line

Share this post


Link to post
Share on other sites
I found the solution

It was an access error, i dont know why i got ENOENT instead of EACCES :|
It was an NTFS fs (im on mac) and i didnt realize i uninstall ntfs3g days before. (i forget what the problem was, i thought ntfs3g was tied to it, it wasnt)

installed it and my code works great.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement