|
Vikrant for VC++ wrote: I remember there was something that allowed to do some code & full excel was there in a Doc / View Application , but i could not remember that.
Check out MSDN for "Some APIs".
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
Did yo try searching the site?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi all,
How can one remove the backslashes froma string(path) to get the filename.
For example you have a path: C:\<dir>\testfile.txt
Now I want to get only the testfile.txt part.
I wrote a function, but it doesn't do exactly what I want, can anyone help.
static char *FindLastSlash(char *Ptr)
{
char c;
char *LastPtr = NULL;
while(1)
{
c = *Ptr;
if(c=='\\') LastPtr = Ptr;
if(c=='\0') break;
Ptr++;
}
return LastPtr;
}
Mant thanx,
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
There's an API which does this exactly (getting a full path and returning only the file name); unfortunately, i can't remember its exact name, nor having time to search it.
search the MSDN a little on "files API"... you would find some useful help
|
|
|
|
|
Programm3r wrote: Now I want to get only the testfile.txt part.
You can use CString::ReverseFind() and then use CString::TrimLeft()/CString::TrimRight() to get what you want.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
Change it to,
static char *FindLastSlash(char *Ptr)
{
char* pFileName = NULL;
pFileName = strrchr(Ptr, '\\');
if (pFileName) pFileName++;
return pFileName;
}
Note that the pointer returned is the part of Ptr string, no new memory is allocated here.
or as mentioned by toxcct, you can use,
PathFindFileName(..)
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
|
Your original code example will break on some DBCS paths.
|
|
|
|
|
Michael Dunn wrote: will break on some DBCS paths
Sry i didn't know whts DBCS path is. Can u give me an example..
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
|
Oh its Double Byte.. i thought it as DataBase and
The code is for Single byte charecter set.
Function Parameter, return value, APIs used all are for single byte, and you cann't pass a DBCS or MBCS to this method, so it won't break.
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
|
I was trying to remember it's name. PathFindFileName is the way!
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir?
Dr.Brad :Well,I just replied to everything Graus did and then argued with Negus for a bit.
|
|
|
|
|
For Shell API's look for API's starting with Path.. or SH.. . Thats the way to go.
|
|
|
|
|
Thank you prasad_som,
I found this works aswell....
HANDLE Handle;
WIN32_FIND_DATA FindData;
Handle = FindFirstFile(fileName, &FindData);
if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
else
{
Ptr = FindData.cFileName;
.....
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
prasad_som wrote: Use PathFindFileName[^] instead.
Actually PathStripPath() is the right one to use na?
nave
|
|
|
|
|
Naveen R wrote: Actually PathStripPath() is the right one to use na?
You can use this function,too. In addition to originally suggested.
Remember PathStripPath strips original string.
|
|
|
|
|
What made me think the PathStripPath better is that, in the docmentation of the PathFindFileName in MSDN, it says the function "Searches a path for a file name.". I think this will invoke some disc operation where as the PathStripPath only need to work on the buffer. I am not sure..... What do you think about this?
nave
|
|
|
|
|
Naveen R wrote: "Searches a path for a file name.".
This means, searches path mentioned in buffer.
Naveen R wrote: I think this will invoke some disc operation
No, it doesn't.
Naveen R wrote: where as the PathStripPath only need to work on the buffer
As said earlier, both version works on buffer. But, PathStripPath strips(modifies) original buffer , passed as input. Which may be not needed. Again, need to use these functions according to need.
|
|
|
|
|
prasad_som wrote: This means, searches path mentioned in buffer.
I misunderstood..
thank you prasad
nave
|
|
|
|
|
Welcome.
|
|
|
|
|
Before return LastPtr line add the line LastPtr++ and everything wil be fine.
Happy coding
Get the facts or facts will get you and when you get them, get them right or they will get you wrong.
Happy Coding
|
|
|
|
|
I have to implement a string search in a file I have problem in using fgetc because i am alternative characters from the file.
S.Yamini
|
|
|
|
|
Can you explain it better?
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|