Board index » delphi » searching for a directory.

searching for a directory.

Hi.  Can someone please tell me how to check if a directory exists.  In my
program, I ask the user for a path and a filename to restore a file from.  I
got it to check if the file exists.  If it doesn't it exist, it displays an
error message. But, if the directory or drive does not exist, the program
crashes.

also...currently, I ask the user for the path and filename separatly eg.
Enter path:  a:\
Enter filename:  test.dat
I then can check if the filename variable is valid (8 characters).  Then, I
add the path and the filename together.  How can I ask the user to enter a
path and a filename at the same time (eg. Eg. Please enter a file to
restore:  a:\test\file.dat ) and then check if the filename is less than
8characters (less than 12 characters including the extention)

thanks!!!!!!!!!!

Nick

 

Re:searching for a directory.


In article <rlJP4.1775$tg1.37...@news2.randori.com>,

Quote
Nick <soc...@mailroom.com> wrote:
>Hi.  Can someone please tell me how to check if a directory exists.

Try to open a file nul from that directory. Remember to close it also.

Osmo

Re:searching for a directory.


umm.... what is a file nul ?

thanks...

Quote
"Osmo Ronkanen" <ronka...@cc.helsinki.fi> wrote in message

news:8eno02$f1q$1@kruuna.Helsinki.FI...
Quote
> In article <rlJP4.1775$tg1.37...@news2.randori.com>,
> Nick <soc...@mailroom.com> wrote:
> >Hi.  Can someone please tell me how to check if a directory exists.

> Try to open a file nul from that directory. Remember to close it also.

> Osmo

Re:searching for a directory.


In article <q9KP4.1779$tg1.41...@news2.randori.com>,

Quote
Nick <soc...@mailroom.com> wrote:
>umm.... what is a file nul ?

It is a device. Dos can open it from any valid directory.

Osmo

Re:searching for a directory.


Quote
On Tue, 02 May 2000 23:16:39 GMT, "Nick" <soc...@mailroom.com> wrote:
>Hi.  Can someone please tell me how to check if a directory exists.  In my
>program, I ask the user for a path and a filename to restore a file from.  I
>got it to check if the file exists.  If it doesn't it exist, it displays an
>error message. But, if the directory or drive does not exist, the program
>crashes.

Are you turning off I/O checking with {$I-}...{$I+} and checking
IoResult after attempting to open the file? IMHO that would be a
better guide as to whether it is possible to open the file in that
directory, than simply checking for the existance of the directory.
IoResult will be 2 for file not found, if you're opening a file to
read it, 3 for Path Not Found and other non-0 values for other errors.

Quote
>also...currently, I ask the user for the path and filename separatly eg.
>Enter path:  a:\
>Enter filename:  test.dat
>I then can check if the filename variable is valid (8 characters).  Then, I
>add the path and the filename together.  How can I ask the user to enter a
>path and a filename at the same time (eg. Eg. Please enter a file to
>restore:  a:\test\file.dat ) and then check if the filename is less than
>8characters (less than 12 characters including the extention)

fsplit will chop the path, file name and extension into separate
strings for you. It's in the DOS unit, and in the online help.
Quote
>thanks!!!!!!!!!!

>Nick

Other Threads