Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

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.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-01-2008, 12:03 PM
Gordack Gordack is offline
Newbie
 
Join Date: Apr 2007
Posts: 4
Credits: 0
Rep Power: 0
Gordack is on a distinguished road
Default Whether a given file argument is a directory or not ?

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);

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 01-01-2008, 04:27 PM
Freedom Doc Freedom Doc is offline
Newbie
 
Join Date: Dec 2007
Posts: 8
Credits: 0
Rep Power: 0
Freedom Doc is on a distinguished road
Default

Quote:
Originally Posted by Gordack View Post
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);

}
After doing your stat() call, you can do

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -5. The time now is 01:02 AM.

Contest Stats

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

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 82%

Ads