Connecting Tech Pros Worldwide Forums | Help | Site Map

problem listing files in a directory

Jrdman
Guest
 
Posts: n/a
#1: Jul 2 '08
hi.
i wrote that code to list the files existed in "c:\" but it doesn't
seem to work cuz when i excute it it dosn't list all the exitsed files
in "c:\"
can someone tell me what's wrong ?
thanks.
#include<stdio.h>
#include<dir.h>

#define FILE_NOT_FOUND (-1)
int main(int argc,char *argv[])
{

_finddata_t finddata;

long hfile;
hfile=_findfirst("c:\*.*",&finddata);
while(_findnext(hfile,&finddata)!= FILE_NOT_FOUND){
printf("%s\n",finddata.name);
}
_findclose(hfile);
getchar();
return 0;
}

Richard Tobin
Guest
 
Posts: n/a
#2: Jul 2 '08

re: problem listing files in a directory


In article <257a1e7d-57c0-4275-ba76-33a7e0912197@d45g2000hsc.googlegroups.com>,
Jrdman <ahmed.bou23@gmail.comwrote:
Quote:
hfile=_findfirst("c:\*.*",&finddata);
If you want a string with a backslash in it, you need to use "c:\\*.*".

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Barry Schwarz
Guest
 
Posts: n/a
#3: Jul 3 '08

re: problem listing files in a directory


On Wed, 2 Jul 2008 05:58:49 -0700 (PDT), Jrdman
<ahmed.bou23@gmail.comwrote:
Quote:
>hi.
>i wrote that code to list the files existed in "c:\" but it doesn't
>seem to work cuz when i excute it it dosn't list all the exitsed files
>in "c:\"
>can someone tell me what's wrong ?
>thanks.
>#include<stdio.h>
>#include<dir.h>
>
>#define FILE_NOT_FOUND (-1)
>int main(int argc,char *argv[])
>{
>
_finddata_t finddata;
>
long hfile;
hfile=_findfirst("c:\*.*",&finddata);
If you didn't see a diagnostic here you need to up your warning level
or find a competent compiler. \* is not a valid sequence.
Quote:
while(_findnext(hfile,&finddata)!= FILE_NOT_FOUND){
printf("%s\n",finddata.name);
>}
>_findclose(hfile);
>getchar();
return 0;
>}

Remove del for email
rahul
Guest
 
Posts: n/a
#4: Jul 3 '08

re: problem listing files in a directory


On Jul 2, 5:58 pm, Jrdman <ahmed.bo...@gmail.comwrote:
Quote:
hi.
i wrote that code to list the files existed in "c:\" but it doesn't
seem to work cuz when i excute it it dosn't list all the exitsed files
in "c:\"
can someone tell me what's wrong ?
thanks.
#include<stdio.h>
#include<dir.h>
>
#define FILE_NOT_FOUND (-1)
int main(int argc,char *argv[])
{
>
_finddata_t finddata;
>
long hfile;
hfile=_findfirst("c:\*.*",&finddata);
while(_findnext(hfile,&finddata)!= FILE_NOT_FOUND){
printf("%s\n",finddata.name);}
>
_findclose(hfile);
getchar();
return 0;
>
}
Strictly off-topic, as you are using a particular API which is not
covered by C standards. By the way, either use an escaped '\' or use a
'/'. Windows accepts both '\' and '/' as path separator.
Closed Thread