directory exist?
Isn't that why we have PB's FileSize() command??
Returns -2 if directory exists 
Code: Select all
Syntax:
Result = FileSize(FileName$)
Description:
Returns the size of the specified file.
Special 'Result' values:
-1: File not found.
-2: File is a directory.
Re: directory exist?
Why do you want to find out?Dreglor wrote:i need some sort of way to find out if a directory exists
In case you just want to make sure the directory path exists, you can use:
MakeSureDirectoryPathExists_(path)
Horst.
- NoahPhense
- Addict

- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
Re: directory exist?
lol.. nicehorst wrote:MakeSureDirectoryPathExists_(path)
- np
Re: directory exist?
> In case you just want to make sure the directory path exists, you can use:
> MakeSureDirectoryPathExists_(path)
That will create the directory if it doesn't exist, which might not be the
desired action. You should only use that if you WANT the directory to
exist. However, if you need to check if ALREADY exists, use FileSize and
check for -2, just like it says in the docs. For example:
See also: http://www.purebasic.com/documentation/ ... esize.html
> MakeSureDirectoryPathExists_(path)
That will create the directory if it doesn't exist, which might not be the
desired action. You should only use that if you WANT the directory to
exist. However, if you need to check if ALREADY exists, use FileSize and
check for -2, just like it says in the docs. For example:
Code: Select all
dir$="c:\xxx\yyy\zzz" ; Our app will check if this dir exists.
If FileSize(dir$)=-2
Debug "Yep, the dir exists, and I didn't create it!"
Else
Debug "No, the dir DOES NOT exist, but I will create it now..."
MakeSureDirectoryPathExists_(dir$)
EndIf
-
GreenGiant
- Enthusiast

- Posts: 252
- Joined: Fri Feb 20, 2004 5:43 pm
PB I was playing with your code and realised that if I ran it two times I was still getting the "No, the dir DOES NOT exist, but I will create it now..." message. Had a look and realised you missed a '\' from your code. I think it should be Or at least that's what seems to work for me.
Code: Select all
dir$="c:\xxx\yyy\zzz\"

