|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hello guys.
Happy new year ! ![]() I have a question about stat() function. Im trying to check if a given file argument is a directory or not, using stat() function ? I couldnt find any examples. Can u help me with this ? I found a small example but it doesnt help me. Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
struct stat buf;
stat(argv[1],&buf);
exit(0);
}
|
| Sponsored Links |
|
|
|
|||
|
Quote:
bool is_dir = buf.st_mode & S_IFDIR; (Assuming C++ and that you have included <sys/stat.h>) Then is_dir is true if and only if argv[1] is a directory. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Project: ionFiles - Joomla Simple File Download | Jordan | Community Projects | 306 | Yesterday 07:35 PM |
| Windows XP Tricks & Tips!!!!..new ones. | pranky | Tutorials | 9 | 08-23-2008 03:22 PM |
| Batch File Help | ineedhelp | General Programming | 4 | 11-15-2007 07:04 PM |
| text file manipulations in vb6.0 | Ronin_paes | Visual Basic Programming | 3 | 06-11-2007 04:54 AM |
| Directory Size | John | PHP Forum | 5 | 08-06-2006 01:02 PM |
| Xav | ........ | 1333.07 |
| MeTh0Dz|Reb0rn | ........ | 1059.52 |
| John | ........ | 887.37 |
| morefood2001 | ........ | 879.43 |
| marwex89 | ........ | 869.98 |
| WingedPanther | ........ | 851.68 |
| Brandon W | ........ | 764.23 |
| chili5 | ........ | 312.39 |
| Steve.L | ........ | 254.16 |
| dcs | ........ | 225.25 |
Goal: 100,000 Posts
Complete: 82%