 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Randall Parker Guest
|
Posted: Mon Apr 26, 2004 3:43 am Post subject: Suppress dialog when DirectoryExists path is for non-existen |
|
|
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
|
Posted: Mon Apr 26, 2004 4:45 am Post subject: Re: Suppress dialog when DirectoryExists path is for non-exi |
|
|
"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
|
Posted: Mon Apr 26, 2004 12:25 pm Post subject: Re: Suppress dialog when DirectoryExists path is for non-exi |
|
|
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
|
Posted: Mon Apr 26, 2004 5:16 pm Post subject: Re: Suppress dialog when DirectoryExists path is for non-exi |
|
|
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
|
Posted: Tue Apr 27, 2004 10:07 am Post subject: Re: Suppress dialog when DirectoryExists path is for non-exi |
|
|
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 |
|
 |
|
|
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
|
|