directory exist?

Everything else that doesn't fall into one of the other PB categories.
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

directory exist?

Post by Dreglor »

i need some sort of way to find out if a directory exists
~Dreglor
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Post by sec »

result=SetCurrentDirectory_(address_to_string_dir_need_check) if exist then result is nonzero, will help you!
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post 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
~Dreglor
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post 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 ;)
Image Image
horst
Enthusiast
Enthusiast
Posts: 197
Joined: Wed May 28, 2003 6:57 am
Location: Munich
Contact:

Re: directory exist?

Post 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)
Horst.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: directory exist?

Post by NoahPhense »

horst wrote:MakeSureDirectoryPathExists_(path)
lol.. nice

- np
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

well that command there horst will make my life a little easier :)
thx
~Dreglor
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: directory exist?

Post 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
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

well i got that fixed :)
thx guys
~Dreglor
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post 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

Code: Select all

 dir$="c:\xxx\yyy\zzz\"
Or at least that's what seems to work for me.
Post Reply