Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to Use Directories 1

Status
Not open for further replies.

oop94

Programmer
Jun 14, 2005
31
US
I'm trying to write a program that opens files from a disk without already knowing the filenames or having the user input the filenames. I do not know how to open files without knowing the exact filename and using syntax such as:
in_stream.open("C078C75D.DAT");
out_stream.open("newC078C75D.DAT", ios::app);
Also, I only know how to open files that are in the same location as my program's source file (.cpp file). I would like to know how to open files from the floppy drive while my program is in another drive, such as the C-Drive.
I am hoping to find out how to do these things in order to complete a project given to me for my engineering internship. Any help would be greatly appreciated!
 
All right, well how should I declare HANDLE, FindFirstFile, and LPCTSTR? Thanks again!
 
you do not have to write the function.. it is already defined. If you are using MFC, you should be able to use it.

sorry.. i just tried the link i pasted.. if you scroll down on the left menu (grey!), you will find a link to findfirstfile. the link is for createfile().

the first parameter is the name of the directory where you want to find the first file (i think you should also be able to just tell it to look in c: but i have not tried this- in fact, i have not used this function before!). teh second parameter is a pointer to WIN32_FIND_DATA.. declare one of these and pass teh address. eg

Code:
WIN32_FIND_DATA a;
HANDLE b=findfirstfile("c:\\something", &a);

this should work but as i said i have not used this function before. you can also use FindNextFile to find the next file. this is also defined at the link if you scroll down...
 
Thanks for your help - I'll give this a try
 
Well, I tried it, but I'm not sure if I'm able to use this. What exactly is MFC? And do I place the code you gave me in the body of my code? If so, do I just declare the pointer and that is all? I apologize for my lack of knowledge; I have only a basic understanding of C++.
 
In a nutshell, a somewhat incomplete definition of MFC (Microsoft foundation classes) is that it is a bunch of libraries that you use in c++ to make GUIs.

it should work if you put #include <windows.h> as an include. but i'm not sure, so don't hold me to it!

i would suggest that your first step should be to just make it compile. we'll see if it does what you need later. so, yes.. you should paste the code in some appropriate part of teh body of your program and include windows.h. as i said, i have not used this function before so i'll be learning something too! let me know if you have problems compiling/building it.

if for some reason, you can't build/compile the program with the new lines do this:

(msvc++ 6)
go to Project -> settings, "general" tab (should already on this tab if you have not modified any other settings). you will see "Microsoft Foundation Classes" with a drop down menu whihc will proabbly be set to "Not using MFC". change this to "Use MFC in a shared DLL".

if that does not work either, let me know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top