Pelles C forum
C language => Beginner questions => Topic started by: junko on July 23, 2011, 11:51:15 PM
-
is this possible ?
-
GetFileInformationByHandleEx (http://msdn.microsoft.com/en-us/library/aa364953%28VS.85%29.aspx) can be used to get this information, but there are requirements for Windows versions below Vista.
-
I know this is a dumb question... but why wouldn't you save the filename you used to open it?
-
GetFileInformationByHandleEx (http://msdn.microsoft.com/en-us/library/aa364953%28VS.85%29.aspx) can be used to get this information, but there are requirements for Windows versions below Vista.
thank you very much
i'm sorry i forgot to mention, i'm talking about FILE stream handle
(i know how to convert to windows api hanlde)
because i want to use crossplatforms functions
-
Once again... you had to have the filename to open the file, whether it is by fopen() or CreateFile().
If the filename is user input, you already have it in a string, just save the string.
If the filename is "hard coded" make it a #define and use that.
The point being that in order to open the file you had to know it's name at some point... why would you not just use that?
#define FILENAME "c:\\myspace\\myfile.txt" // global filename
// later
FILE *fp = fopen(FILENAME,"r+");
// still later
printf("The filename is : %s,FILENAME);
or
char FileName[256] = {0}; // declared at global scope
// later
fprint("Enter the filename : ");
fgets(FileName,255,stdin);
fopen(FileName,"r+");
// still later
printf(The filename is : %s",FileName);
-
i think i know how to save the file name when i open it, thanks :)
it's not relevant here because the file is opened by a user,
and i don't want to save the user input
so i'm looking for a way to retrieve this from the file handle,
which i'm sure it's possible,
since the stream probably knows its destination :)
the answer of stephen is good, i'm just curious maybe there is
an os independent function to do this.
-
i think i know how to save the file name when i open it, thanks :)
it's not relevant here because the file is opened by a user,
and i don't want to save the user input
so i'm looking for a way to retrieve this from the file handle,
which i'm sure it's possible,
since the stream probably knows its destination :)
the answer of stephen is good, i'm just curious maybe there is
an os independent function to do this.
Ok, well, good luck with that...