find file in C - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

find file in C

riazrahamanriazrahaman Posts: 1Member
Hi guys..
i need to write a program to search the complete system for a
particular file in C language...for eg: i want to search *.txt files
in C drive and my program should search the complete C drive as well
as the subdirectories and display them...can anyone help me out...i
used the function findfirst() but it does a search only in the
current directory or the specified directory and not the sub-
directories.

Looking forward for ur help

Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    : Hi guys..
    : i need to write a program to search the complete system for a
    : particular file in C language...for eg: i want to search *.txt files
    : in C drive and my program should search the complete C drive as well
    : as the subdirectories and display them...can anyone help me out...i
    : used the function findfirst() but it does a search only in the
    : current directory or the specified directory and not the sub-
    : directories.
    :
    : Looking forward for ur help
    :
    :

    modify this to suit your needs

    http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=585&MsgID=174802&Setting=A9999F0001


  • pseudocoderpseudocoder Posts: 688Member ✭✭✭
    : : Hi guys..
    : : i need to write a program to search the complete system for a
    : : particular file in C language...for eg: i want to search *.txt files
    : : in C drive and my program should search the complete C drive as well
    : : as the subdirectories and display them...can anyone help me out...i
    : : used the function findfirst() but it does a search only in the
    : : current directory or the specified directory and not the sub-
    : : directories.
    : :
    : : Looking forward for ur help

    From Borland's library reference. (dino dos) However, you can modify this to walk through a drive searching for any file type.
    [code]
    #include
    #include
  • stoberstober Posts: 9,765Member ✭✭✭
    [b][red]This message was edited by stober at 2004-3-13 13:22:29[/red][/b][hr]
    : stober, thanks for posting this link. I was interested in the winapi version of the above.
    :


    Huh? The link I gave you [b]does[/b] use winapi functions. As I said before, you can easily modify it to just print out the file names instead of deleting them.


  • pseudocoderpseudocoder Posts: 688Member ✭✭✭
    : [b][red]This message was edited by stober at 2004-3-13 13:22:29[/red][/b][hr]
    : : stober, thanks for posting this link. I was interested in the winapi version of the above.
    : :
    :
    :
    : Huh? The link I gave you [b]does[/b] use winapi functions. As I said before, you can easily modify it to just print out the file names instead of deleting them.
    :
    :
    :

    Now I'm confused. :( I was thanking you for providing a winapi solution. The dos code that I posted is what I meant by "winapi version of the above." :)

    Perhaps you thought it was the OP of this thread?

  • stoberstober Posts: 9,765Member ✭✭✭
    Sorry if I misunderstood. Either the Win32 API functions (FindFirstFile() and FindNextFile()) or the more generic _findfirst() and _findnext() accomplish the same thing when run under Windows, and the coding algorithm is the same. That is, neither do subdirectories by themselves. If you want to process subdirectories then your code must do that. The algorithm I provided processes subdirectories by recursive functions calls, which is probably the most common way to do that.
Sign In or Register to comment.