7 Replies - 1036 Views - Last Post: 19 July 2008 - 07:23 AM Rate Topic: -----

#1 yunus_sys   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-May 08

need help on "Searching for the given type of file" using C

Posted 18 July 2008 - 04:10 AM

Hi,

I need a C program to search for the specific type of file in the specified drive. For example if I give file name as "test" it has to search for all the files with there starting name as "text" irrespective of the remaining characters. Also if I give file type extension as ".txt" it has to display all "txt" files in that location. Please help me. Itís an urgent.
Is This A Good Question/Topic? 0
  • +

Replies To: need help on "Searching for the given type of file" using C

#2 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1435
  • View blog
  • Posts: 11,009
  • Joined: 06-February 08

Re: need help on "Searching for the given type of file" using C

Posted 18 July 2008 - 05:23 AM

It's an urgent what?

This is pretty simple if you put some thought into it.

[rules][/rules]
Was This Post Helpful? 1
  • +
  • -

#3 F!st!cuffs   User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 153
  • Joined: 15-July 08

Re: need help on "Searching for the given type of file" using C

Posted 18 July 2008 - 08:18 PM

why can't you just use search?
Was This Post Helpful? 0
  • +
  • -

#4 born2c0de   User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Re: need help on "Searching for the given type of file" using C

Posted 18 July 2008 - 10:40 PM

What is your target platform?
If you're using Windows, use the findfirst() function from io.h.
Specify "*.txt" as the wildcard parameter and pass it as the first argument to the function.
Was This Post Helpful? 0
  • +
  • -

#5 yunus_sys   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-May 08

Re: need help on "Searching for the given type of file" using C

Posted 19 July 2008 - 06:15 AM

Hi,

I have written this code, but it seems some thing wrong with this. Please help me to solve this. I want this application in DOS or windows environment. If possible please provide me the full coed.

Thanks a lot.

# include <stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char fname[12];
char first[8], ext[3], command[100];
int i=0;
clrscr();
printf("Enter file name : ");
scanf("%s",&fname);
 // fflush(stdin);
// get(fname);
while(fname[i]!=".") //INVALID INDIRECTION//AND//TOO FEW PARAMETERS IN CALL TO STRCMP
{
first[i]=fname[i]; //INVALID INDIRECTION//
i++;
}
while(fname[i]!="/0") //INVALID INDIRECTION//
{
ext[i]=fname[i];  //INVALID INDIRECTION//
i++;
}
strcat(command,"dir ");
if(strcmp(first,NULL)!=0)
strcat(command,first);
if(strcmp(ext,NULL)!=0)
{
strcat(command,".");
strcat(command,ext);
}
}

Was This Post Helpful? 0
  • +
  • -

#6 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1435
  • View blog
  • Posts: 11,009
  • Joined: 06-February 08

Re: need help on "Searching for the given type of file" using C

Posted 19 July 2008 - 07:01 AM

Do not use the thanks feature to ask me for help.
Was This Post Helpful? 0
  • +
  • -

#7 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3212
  • View blog
  • Posts: 19,240
  • Joined: 14-September 07

Re: need help on "Searching for the given type of file" using C

Posted 19 July 2008 - 07:05 AM

:ph34r:
Was This Post Helpful? 0
  • +
  • -

#8 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1435
  • View blog
  • Posts: 11,009
  • Joined: 06-February 08

Re: need help on "Searching for the given type of file" using C

Posted 19 July 2008 - 07:23 AM

Posted Image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1