opendir problem

hi every body

i tried to open a directory in my local computer but the function opendir() always
return error "can not open the directory "
i send the following directory names

- "."
- c:\\src\\

and alot of directories witch r exist in my PC
please i need heeeeeeeeeeeelp
Note : my windows is 7 and i work in c++ win32 console application in .net2008

¿what does perror() say?
I think that you can use forward slashes in the path.
Hi
I Think .Net should have it's own library or class, I am not sure but it shlud be some thing like FindFirstFile and FindNextFile , to handle directroy and file system input out issues. Why do you use opendir ?
i tried this code :


#include "stdafx.h"
#include <dirent.h>

int _tmain(int argc, _TCHAR* argv[])
{
DIR *dir;
struct dirent *ent;
const char* path="D:\\banat";
dir = opendir (path);

if (dir != NULL)
{
while ((ent = readdir (dir)) != NULL)
{
printf("%s\n",ent->d_name);
}
}
else
{
printf("%s\n","Cannot open directory!");
}
char ch=getchar();
return 0;
}

i tried changing the slashes and that path and i tried a lot of codes but it still can not open the directory
Last edited on
[code] "Please use code tags" [/code]
Again, ¿what does perror() say?
1
2
3
4
5
6
7
#include <stdio.h>

DIR *dir = opendir(path);
if(dir){
//...
}
else perror("Cannot open directory");


man opendir wrote:
The opendir() and fdopendir() functions return a pointer to the directory stream. On error, NULL is returned, and errno is set appropriately.


man perror wrote:
The routine perror() produces a message on the standard error output, describing the last error encountered during a call to a system or library function
(...)The error number is taken from the external variable errno, which is set when errors occur but not cleared when successful calls are made.
opendir/readdir/closedir are POSIX system calls. As you're using Windows, you should be using Windows system calls FindFirstFile/FindNextFile/FindClose.

Alternatively, you can use a cross-platform solution (like Boost).

There is no dirent.h supplied with the Microsoft C/C++ compilers.
perror() say : "no such file or directory" and i'm sure 100% that the path exist
Topic archived. No new replies allowed.