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 

Suppress dialog when DirectoryExists path is for non-existen

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





PostPosted: Mon Apr 26, 2004 3:43 am    Post subject: Suppress dialog when DirectoryExists path is for non-existen Reply with quote



When doing:
bool DirExistsFlag = DirectoryExists(SomePathStr);
with app built with BCB v6 sp4 Windows 2000 will pop up a dialog that says:
"There is no disk in the drive. Please insert a disk into drive D:"

Okay, this can be for a number of reasons, such as:
- A CD-ROM drive has no disk in it.
- some other removable drive isn't there.
- There is no drive letter at all on this machine.
- The path is for a network drive that is not reachable.

The network drive possibility means one can't count on the first letter of the path
to be a drive letter. So one can't simply translate the first letter into a drive vol
and then, say, test its size with an OS call.

So here are my questions:

1) Is there any way to suppress dialog pop-ups while doing the DirectoryExists call?

2) Is there some other call for testing whether a path is for a legal volume and
legal directory?

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Apr 26, 2004 4:45 am    Post subject: Re: Suppress dialog when DirectoryExists path is for non-exi Reply with quote




"Randall Parker" <STOPtechiepundit (AT) EVILfuturePOXpunditSPAM (DOT) com> wrote in
message news:408c85db$1 (AT) newsgroups (DOT) borland.com...

Quote:
1) Is there any way to suppress dialog pop-ups
while doing the DirectoryExists call?

Look at the Win32 API SetErrorMode() function.


Gambit



Back to top
Mark Jacobs
Guest





PostPosted: Mon Apr 26, 2004 12:25 pm    Post subject: Re: Suppress dialog when DirectoryExists path is for non-exi Reply with quote



To try to change to drive D:, try this :-

int origdrive=getdisk();
setdisk(3);
if (getdisk()!=3)
{
setdisk(origdrive); ShowMessage("Could Not Change to Drive D:");
}

setdisk does not cause any messages to appear when the drive is non-existent or unready.
setdisk returns the total number of drives, so we have to use getdisk to check that the drive change happened
successfully.
if it didn't change drive, we restore the drive you were on (*YOU HAVE TO DO THIS*). The following routine
looks at each drive letter (A-Z) and checks what type of drive it is. It builds a list of drive letters
accessible on that system :-

AnsiString mjgetdrives()
{
AnsiString dsp="",dvch; int disk,drvtyp; __int64 dsz;
for (disk=0;disk<26;++disk)
{
try
{
dvch=AnsiString((char)(disk+'A'))+":"; drvtyp=GetDriveType((dvch+"\").c_str());
if (drvtyp==DRIVE_REMOVABLE || drvtyp==DRIVE_CDROM) dsz=1; else dsz=DiskSize(disk+1);
}
catch (Exception &excp)
{
dsz=0;
}
if (dsz>0) dsp+=dvch+" ";
}
return dsp;
}

That should give you some ideas. Regards,

--
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
[email]markj (AT) criticalremovethisspuriousantispamstuff (DOT) co.uk[/email]

"Randall Parker" <STOPtechiepundit (AT) EVILfuturePOXpunditSPAM (DOT) com> wrote

Quote:
When doing:
bool DirExistsFlag = DirectoryExists(SomePathStr);
with app built with BCB v6 sp4 Windows 2000 will pop up a dialog that says:
"There is no disk in the drive. Please insert a disk into drive D:"

Okay, this can be for a number of reasons, such as:
- A CD-ROM drive has no disk in it.
- some other removable drive isn't there.
- There is no drive letter at all on this machine.
- The path is for a network drive that is not reachable.

The network drive possibility means one can't count on the first letter of the path
to be a drive letter. So one can't simply translate the first letter into a drive vol
and then, say, test its size with an OS call.

So here are my questions:

1) Is there any way to suppress dialog pop-ups while doing the DirectoryExists call?

2) Is there some other call for testing whether a path is for a legal volume and
legal directory?




Back to top
Randall Parker
Guest





PostPosted: Mon Apr 26, 2004 5:16 pm    Post subject: Re: Suppress dialog when DirectoryExists path is for non-exi Reply with quote

But Mark, this won't work for network drives that are not mapped to a drive letter
will it?

A person could specify a path that does not include a drive letter because they could
use a bigger volume name, right?

Mark Jacobs wrote:
Quote:
The following routine
looks at each drive letter (A-Z) and checks what type of drive it is. It builds a list of drive letters
accessible on that system :-

AnsiString mjgetdrives()
{
AnsiString dsp="",dvch; int disk,drvtyp; __int64 dsz;
for (disk=0;disk<26;++disk)
{
try
{
dvch=AnsiString((char)(disk+'A'))+":"; drvtyp=GetDriveType((dvch+"\").c_str());
if (drvtyp==DRIVE_REMOVABLE || drvtyp==DRIVE_CDROM) dsz=1; else dsz=DiskSize(disk+1);
}
catch (Exception &excp)
{
dsz=0;
}
if (dsz>0) dsp+=dvch+" ";
}
return dsp;
}

Back to top
Mark Jacobs
Guest





PostPosted: Tue Apr 27, 2004 10:07 am    Post subject: Re: Suppress dialog when DirectoryExists path is for non-exi Reply with quote

You can map a temporary drive letter to the UNC path, and then use setdisk. Here's how to map a virtual drive
letter to a server somewhere else :-

bool mjmapdrive(AnsiString netrsc,AnsiString locnam,bool perm)
{
DWORD dwFlags=0,dres; NETRESOURCE mjnr;
int ii=netrsc.Length();
if (perm) dwFlags=CONNECT_UPDATE_PROFILE;
WNetCancelConnection2(locnam.c_str(),0,true);
if (netrsc[ii]=='\') netrsc=netrsc.SubString(1,ii-1);
mjnr.dwType=RESOURCETYPE_DISK; mjnr.lpLocalName=locnam.c_str();
mjnr.lpRemoteName=netrsc.c_str(); mjnr.lpProvider=NULL;
dres=WNetAddConnection2(&mjnr,NULL,NULL,dwFlags);
return (dres==NO_ERROR);
}

--
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
[email]markj (AT) criticalremovethisspuriousantispamstuff (DOT) co.uk[/email]

"Randall Parker" <STOPtechiepundit (AT) EVILfuturePOXpunditSPAM (DOT) com> wrote

Quote:
But Mark, this won't work for network drives that are not mapped to a drive letter
will it?

A person could specify a path that does not include a drive letter because they could
use a bigger volume name, right?

Mark Jacobs wrote:
The following routine
looks at each drive letter (A-Z) and checks what type of drive it is. It builds a list of drive letters
accessible on that system :-

AnsiString mjgetdrives()
{
AnsiString dsp="",dvch; int disk,drvtyp; __int64 dsz;
for (disk=0;disk<26;++disk)
{
try
{
dvch=AnsiString((char)(disk+'A'))+":"; drvtyp=GetDriveType((dvch+"\").c_str());
if (drvtyp==DRIVE_REMOVABLE || drvtyp==DRIVE_CDROM) dsz=1; else dsz=DiskSize(disk+1);
}
catch (Exception &excp)
{
dsz=0;
}
if (dsz>0) dsp+=dvch+" ";
}
return dsp;
}



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.