file attributes

March 28, 2009 by admin  
Filed under C

#include
#include

int main()
{
int mode;
/*check a files attributes*/
mode = access(”f:/cprojects/urls.txt”,0);
if(mode)
printf(”File does not exist.n”);
else
/*check if the file can be written to*/
mode = access(”f:/cprojects/urls.txt”,2);
if(mode)
printf(”File cannot be written.n”);
else
printf(”file can be written to.n”);

/*check if file can be read*/
mode = access(”f:/cprojects/urls.txt”,4);
if(mode)
printf(”File cannot be read.n”);
else
printf(”File can be read.n”);

/*check if afile can be read/written*/
mode = access(”f:/cprojects/urls.txt”,6);
if(mode)
printf(”File cannot be read/written to.n”);
else
printf(”File can be read/written to.n”);

return 0;
}

Related posts:

  1. get the size of a file #include #include #include #include int main() { int fp; long...
  2. Simple PHP counter This is a simple counter example with PHP, this example...
  3. Another file example #include #include int main() { // first lets output to...
  4. exe file information #include struct EXEHEAD { char id[2]; // ‘M’ & ‘Z’...
  5. Absread example #include #include #include #include int main(void) { unsigned char buffer[512];...

Related posts brought to you by Yet Another Related Posts Plugin.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!