How to see if a file exists with a different extension

This is a discussion on How to see if a file exists with a different extension within the C++ Programming forums, part of the General Programming Boards category; Hello, all! I am trying to write a program that will check to see if a file with a different ...

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

    How to see if a file exists with a different extension

    Hello, all! I am trying to write a program that will check to see if a file with a different extension exists for the file that was inputed. That was really confusing, so how a bout an example? Lets say the user inputed (from a command prompt in win32):
    myprog data.txt

    I want my program to check an see if a file with the name data.dat exists and if it does pass both names as an argument to another program. For example:
    otherprog data.txt data.dat

    Is there any easy way to go about this? Keep in mind that I am relatively new to programming, so try to keep it simple . Thanks!
    -PCJason

    PCJason@techie.com

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You can enumerate files with different extensions using _findfirst()/_findnext() in io.h or FindFirstFile()/FindNextFile() in windows.h using wildwards. If you need an example of how these functions work do a search on their names.
    zen

  3. #3
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Since you are new to CProgramming.com, may I suggest some things for you? First try to do it on your own, some people get very agrivated with the type of question you asked. Second post some code that you are having problems with, this will show that you are trying to do it yourself. Third do some searches.

    Search:
    Google
    MSDN
    CProgrmming

    You will get answers from at least one of those URL's.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    2
    SOrry about that, I guess I should have gotten used to the attitude around here . Anyway, I have been using some resources off of the net, and I think I am making progress, unfortunately, it won't compile. I will continue working on it, but I may post the source if I still can't get it. Thanks for your time
    -PCJason

    PCJason@techie.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 01:36 PM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 08:01 PM

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