![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PHP 5 solaris opendir failure | Esaia | Shell Programming and Scripting | 1 | 05-25-2008 08:08 PM |
| Listing directories and sub directories | jinxor | UNIX for Advanced & Expert Users | 3 | 03-11-2008 07:27 AM |
| moving directories to new directories on multiple servers | mackdaddy07 | Shell Programming and Scripting | 0 | 04-06-2007 08:30 AM |
| Two Files Created For Every One? | Atama | UNIX for Dummies Questions & Answers | 1 | 04-12-2002 01:44 PM |
| Created FilePermission | Reza Nazarian | UNIX for Dummies Questions & Answers | 6 | 10-19-2001 05:16 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
opendir() + customly created directories
Gday all
In a program I am designing, I am using opendir() to test whether entries under a certain directory are sub-directories or not. This method works fine for the directory itself (.) and the parent directory (..), however it does not work for any sub-directories I manually create. i.e. it does not work for current_directory/my_sub_directory I am performing the test in the following manner Code:
if( (sub_dir = opendir(sub_dir_name)) != NULL)
{
/* Do whatever*/
}
regards James |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
One trap I always keep falling into is forgetting to glue back the entry from a readdir to the directory I read it from, i.e. using a relative file name in the wrong (e.g. grandparent) directory.
|
|
#3
|
|||
|
|||
|
Quote:
|
|
#4
|
|||
|
|||
|
Doubly linked lists..yay.
|
|
#5
|
|||
|
|||
|
hey all
Ive discovered a better way to test for the presence of sub-directories within folders, however it does not involve the use of opendir() What I did instead was the following Code:
/*Check if it is current or parent directory*/
if( (strcmp(subfolder_name,".") != 0) && (strcmp(subfolder_name,"..") != 0)
{
/*Check to see if it is a directory by using strrchr()*/
ptr = strrchr(subfolder_name,'.');
/*If strrchr() returns NULL, the current entry
is indeed a sub-folder*/
if(ptr == NULL)
{
/*Do necessary stuff here*/
}
}
|
|
#6
|
|||
|
|||
|
opendir() returns a pointer to a dir stream. readdir() is invoked in a loop afterwards to read the contents of the opened dir stream. Each dir entry is passed from readdir() to stat() which stores information in a stat structure. The S_ISDIR() macro can be used to test whether the stat structure is a dir or not. Look at the manpages of opendir() readdir() and stat().
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|