need some command...

This is a discussion on need some command... within the C Programming forums, part of the General Programming Boards category; what is a command that i can use to make a prog search the entire hd for a file...? but ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    227

    Question need some command...

    what is a command that i can use to make a prog search the entire hd for a file...? but a need a command that i can use in linux to.. .. please can you show me a simple example on how to use the command cause im a comple nebie to c..

  2. #2
    Unregistered
    Guest
    Win 98 has find.exe, which searches the hard drive, and is 7k in size.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    heh! hhmm maybe i post it wrong... what i mean is... what command can i use that workz in linux(gcc)and in windowz compilar(boland) i really need it more for linux.. then window.. btw... sorry for posting it here i didnt know that there was a board on linux programming here...

  4. #4
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    This will find any file "filename" on your system, provided that you have permission to read the chain of directory entries starting from the given directory (in this case / i.e., the root):

    find / -name filename

    As an alternative (more likely that you want this) you can search only the home directory of the current user:

    find ~ -name filename

    There is also a command that uses a cache file, which is usually updated only once a day, but also is much faster:

    locate \*/filename

    (here \* stands for any number of character, / for the last path separator, and filename for the file you are looking for)

    if you are trying to find where a command program is on your system you should use:

    which filename


    Hope one of these is what you are looking for...

    alex

  5. #5
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    How do u do that in windows? Is there a special command?

  6. #6
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    You don't..

    find under *NIX is not available under DOS/Windows unless you get something like the Cygwin GNU tools.

    To my knowledge there is no command line tools that share a similar interface between *NIX and Windows.

    You could write your code to conditionaly compile different calls to the native "find" command to match the particular OS you are operating under at that time.

  7. #7
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    Hi!

    In dos: dir c:\ /s /b
    will give you a listing of all files on the c:-drive.

    If you happen to use the borland C compiler (the free version or you have installed the command-line interface to the commercial versions) then you also get the grep utility:

    dir c:\ /s /b | grep -i -r+ -e \\filename$

    will give of all occurences of "filename"

    Hope this helps...

    alex

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    Hi!
    Code:
    system("find / -name filename >path.out");
    now you can read the file´s path out of "path.out".

    klausi
    When I close my eyes nobody can see me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. problem with "touch" command in c program
    By Moony in forum C Programming
    Replies: 10
    Last Post: 08-01-2006, 09:56 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Ping problem
    By bladerunner627 in forum C++ Programming
    Replies: 12
    Last Post: 02-02-2005, 11:54 AM
  5. exe files in -c- language
    By enjoy in forum C Programming
    Replies: 6
    Last Post: 05-18-2004, 04:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21