Thread: How to check for existance of files

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    How to check for existance of files

    Hi Folks,

    How do I check for the existance of files with a common pattern in any specific directory.

    For eg:
    list of filenames

    x_tmp_y;
    y-tmp_z;
    ....
    ....

    The patter I will check for files that have "_tmp_" as part of their filename.

    Any help in this direction will be greatly appreciated
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Huh? Do you know the pattern before hand? Is the pattern being given to you by someone? Are you trying to figure out if files in a directory have a pattern to them? What are you doing?

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    I know the pattern

    I have a directory in which there could be huge list of files. But only few files in that directory would have a specific text "_tmp_" as part of their filename.

    I have written a block of code that will move all files that have that character as part of the filename to another directory.

    I am using
    Code:
    if(system("mv *_tmp_* /tmp") != 0)
    {
        // print error message
    }
    The situation is that if no files exist, that would fail. So I would like to know whether any file exists at all with that string as part of the file name.

    If it were a single file, I could have happily made use of access() but well this is a different situation all to gether.
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    I am still waiting...

    Hi Guys,

    I am still waiting to see a solution.. in here...
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    You can use the following functions:
    FindFirstFile()
    FindNextFile()
    FindClose()

    I think these are Windows functions, but i don't know of any other...

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    That Won't Solve My Problem

    Thanks for those functions.... but I am working on Sun Solaris... and no such functions exist.....

    So I am still at SQUARE ONE
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  7. #7
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Code:
    FILE *fp;
    system("ls | grep _tmp_ > outfile");
    fp = fopen("outfile","r");
    etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  2. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 02:47 AM
  3. accessing all files in a folder.
    By pastitprogram in forum C++ Programming
    Replies: 15
    Last Post: 04-30-2008, 10:56 AM
  4. spell check in C using a dictionary file
    By goron350 in forum C Programming
    Replies: 10
    Last Post: 11-25-2004, 06:44 PM
  5. check my code ( if statement, file existance )
    By Shadow in forum C Programming
    Replies: 1
    Last Post: 10-04-2001, 11:13 AM