opening file

Started by
6 comments, last by ecaf 21 years, 9 months ago
i want my program to read from itself....it will be easy if the user was not able to rename the file but if the user renames the file how can i make it read its own file name and location...i''m vb programmer and would have written something of this nature maybe this will help... Open App.Path & App.EXEName & ".exe" For Binary As #1 how would i get the same result in c++?? i know how to open and read files using the fstream header...thanx for the help in advance... -face ============================= you laugh at us because we''''re different, we laugh at you because your all the same... =============================
=============================you laugh at us because we''redifferent, we laugh at youbecause your all the same...=============================
Advertisement
1) Why?

2) You can just try opening the file (with the ios::nocreate flag of course); odds are the user won''t rename it. If they do, you can get the path of the executable using certain Win32 functions and search for all EXEs in the directory. If there''s only 1, that''s yours; otherwise you''re out of luck, though there may be better methods out there.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[twitter]warrenm[/twitter]

well the reason i''m doing is for no reason other then a learning experience....i''m binding multiple files together and trying to seperate them individually....anyone have any other ideas?

-face

=============================
you laugh at us because we''''re
different, we laugh at you
because your all the same...
=============================
=============================you laugh at us because we''redifferent, we laugh at youbecause your all the same...=============================
Look at the output of one on these programs (written in C):
#include <stdio.h>int main(int argc, char *argv[]) {	printf("%s\n",argv[0]);	return 0;} 

Or this if you don''t have access to the argc/argv parameters the standard main function provides (if you are using WinMain, for instance):
#include <windows.h>#include <stdio.h>int main(void) {	printf("%s\n",GetCommandLine());	return 0;} 


hey man just what i was looking for that for both versions....much appreciated....

-face

=============================
you laugh at us because we''''re
different, we laugh at you
because your all the same...
=============================
=============================you laugh at us because we''redifferent, we laugh at youbecause your all the same...=============================
As a note: Be careful with those examples, they don''t always give you the exact same results (they first is sometimes prefixed with the path, and the second will contain all kinds of stuff depending on how the program is launched).

If yer using Windows, you can do this:



  #include <windows.h>int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){  char filename[MAX_PATH]; // 260 or so  GetModuleFileName(GetModuleHandle(NULL),filename,MAX_PATH);  MessageBox(NULL,filename,"This File",MB_OK);  return 0;}  

daerid@gmail.com
hey man even better....thanx you guys...you make my life a whole lot simpler...

-face

=============================
you laugh at us because we''''re
different, we laugh at you
because your all the same...
=============================
=============================you laugh at us because we''redifferent, we laugh at youbecause your all the same...=============================

This topic is closed to new replies.

Advertisement