Page 1 of 1
directory exist?
Posted: Sat Jul 03, 2004 1:54 am
by Dreglor
i need some sort of way to find out if a directory exists
Posted: Sat Jul 03, 2004 5:03 am
by sec
result=SetCurrentDirectory_(address_to_string_dir_need_check) if exist then result is nonzero, will help you!
Posted: Sat Jul 03, 2004 5:40 am
by Dreglor
thanks thats exactly what i needed
*edit* wait what does that command do? the name suggests that it not a "if_directory_exist" command
Posted: Sat Jul 03, 2004 6:45 am
by Paul
Isn't that why we have PB's FileSize() command??
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.
Returns -2 if directory exists

Re: directory exist?
Posted: Sat Jul 03, 2004 3:12 pm
by horst
Dreglor wrote:i need some sort of way to find out if a directory exists
Why do you want to find out?
In case you just want to make sure the directory path exists, you can use:
MakeSureDirectoryPathExists_(path)
Re: directory exist?
Posted: Sat Jul 03, 2004 3:56 pm
by NoahPhense
horst wrote:MakeSureDirectoryPathExists_(path)
lol.. nice
- np
Posted: Sat Jul 03, 2004 6:21 pm
by Dreglor
well that command there horst will make my life a little easier

thx
Re: directory exist?
Posted: Sun Jul 04, 2004 4:28 am
by PB
> 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:
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
See also:
http://www.purebasic.com/documentation/ ... esize.html
Posted: Mon Jul 05, 2004 11:51 pm
by Dreglor
well i got that fixed

thx guys
Posted: Tue Jul 06, 2004 12:52 am
by GreenGiant
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.