BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How can understand if my file has this extension?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
b
Guest





PostPosted: Mon Jul 28, 2003 8:46 pm    Post subject: How can understand if my file has this extension? Reply with quote



i open a file in this way:
if(SaveDialog1->Execute() == mrOk)
{
int const size = SaveDialog1->FileName.Length() + 2; // this 2 is for
an possible extension .c
char *filePath;
filePath = new char[size];
strcpy(filePath, SaveDialog1->FileName.c_str());
bool extension = false;
int l = 0;
while((!extension) && (l {
if((filePath[l] == ".") && (filePath[l+1] == "c")) //<------ H E R
E
extension = true;
l++
}

//handle extension


i would understand if the file has a .c extension or not but using this code
i get an error: [C++ Error] Try.cpp(780): E2034 Cannot convert 'char' to
'char *'





Back to top
JD
Guest





PostPosted: Mon Jul 28, 2003 9:07 pm    Post subject: Re: How can understand if my file has this extension? Reply with quote




"b" <borland.public.cppbuilder.vcl.components.using> wrote:

if( SaveDialog1->Execute() )
{

String fExtension = ExtractFileExt( SaveDialog1->FileName );

if( fExtension.Length() > 0 )
{
// there is an extension
}

// or

if( fExtension == "c" || fExtension == "C" )
{
// file extention is 'c'
}

}

~ JD

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Jul 28, 2003 10:49 pm    Post subject: Re: How can understand if my file has this extension? Reply with quote



"b" <borland.public.cppbuilder.vcl.components.using> wrote


Quote:
if(SaveDialog1->Execute() == mrOk)

Execute() returns a bool, not a TModalResult.

if( SaveDialog1->Execute() )

Quote:
int const size = SaveDialog1->FileName.Length() + 2;

Under Windows95+, file extensions are allowed to be very long. You cannot
make any assumptions about the actual length of the extension for the chosen
file.

Quote:
i would understand if the file has a .c extension or not

Rather then going through all of that hassle, why not just use the
ExtractFileExt() function?

if( SaveDialog1->Execute() )
{
AnsiString ext = ExtractFileExt(SaveDialog1->FileName);
if( AnsiSameText(ext, ".c") )
// do something
}


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Jul 28, 2003 10:51 pm    Post subject: Re: How can understand if my file has this extension? Reply with quote


"JD" <nospam (AT) nospam (DOT) com> wrote


Quote:
if( fExtension == "c" || fExtension == "C" )
{
// file extention is 'c'
}

ExtractFileExt() includes the period, so your checks above will always fail.

Also, you can use AnsiSameText() or AnsiCompareIC() to perform 1 check
instead of 2 separate ones.


Gambit



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.