Solved

Return filename from folder! (Urgent)

Posted on 2000-03-27
7
185 Views
Last Modified: 2010-04-15
Could anyone tell me how I get the first file in a folder? I have a function whith one in parameter, witch is a path. In this path i would like too return the first filename it finds.

//Micke_Cap
0
Comment
Question by:Micke_Cap
7 Comments
 
LVL 2

Expert Comment

by:fremsley
ID: 2660560
check the manual pages for the posix

  - opendir
  - readdir
  - closedir

functions.
0
 

Author Comment

by:Micke_Cap
ID: 2660629
Thanks!
0
 
LVL 10

Expert Comment

by:makerp
ID: 2660969
/*
this function recursivly scan directries. you will need to change it so it gets the first file only.

i donr this in VC++ on NT 4.0
*/

#include <stdio.h>
#include <io.h>


int scan_path(char *path)
{
     char spath[256];
     struct _finddata_t ff;
     long fhandle;
      
     sprintf(spath,"%s\\*",path);
     fhandle=_findfirst(spath,&ff);
     if(fhandle==-1L)
     {
          printf("Bad path\n");
          return -1;
     }
     else
     {
          /* loop through each etry in the dir */
          while(!_findnext(fhandle,&ff))
        {
               /* if its a sub-dir then recursivly call our self*/
               if(ff.attrib&_A_SUBDIR)
               {
                     if(strcmp(ff.name,".."))
                     {
                            sprintf(spath,"%s\\%s",path,ff.name);
                            scan_path(path2);
                     }
               }
               else
               {
                     /* if its a file then */
                     if(ff.attrib^_A_SYSTEM)
                     {
                            printf("Found File %s\n",ff.name);
                     }
               }
          }
     }
     return 1;
}
      
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 1

Expert Comment

by:guyss
ID: 2663108
check your manual for help on the findfirst fuction.
0
 

Author Comment

by:Micke_Cap
ID: 2663262
makerp.. write somthing as an answer and I'll giv you the points..
0
 
LVL 10

Accepted Solution

by:
makerp earned 80 total points
ID: 2663271
cheers Micke_Cap

did that help you. i use that bit of code all the time !!!.

you can make it into quite a generic search function and bug it in your own library
0
 

Author Comment

by:Micke_Cap
ID: 2663431
It was werry helpful code.. Thanks.

//Micke_cap
0

Featured Post

Free camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now