digitaldeath
(Fresh Scripter)
2006-03-20 03:14 PM
Check if a directory exists

Hi all,
I've checked the documentation and can only see functions which check if a file exists, but how can I check if a directory exists?

Regards,
Niall.


Les
(KiX Master)
2006-03-20 03:19 PM
Re: Check if a directory exists

same way, it works for both.

digitaldeath
(Fresh Scripter)
2006-03-20 03:22 PM
Re: Check if a directory exists

So for a directory I'd do something like
IF EXIST ("C:\Windows")

and that will return 1 (true)?
I need to check for the existence of a dir and if it doesn't exist, copy it from a Samba share. Can I get a code example of this?


Mart
(KiX Supporter)
2006-03-20 03:40 PM
Re: Check if a directory exists

Something like this?

Code:

If Exist ("c:\somefolder")
?"Folder exists. Do nothing."
Else
?"Folder does not exist. Copy stuff now."
Copy "\\server\share\somefolder\" "c:\" /s
EndIf



NTDOCAdministrator
(KiX Master)
2006-03-20 10:04 PM
Re: Check if a directory exists

Well a folder and a file can have the same name but not be the same
object type so coding something like this might be a little better

I would also recommend using KiXtart v4.52 beta 2 as some routines for file manipulation have recently been updated/corrected.

 
Code:

If GetFileAttr("c:\temp\somefolder") & 16
;Folder exists already - do nothing
Else
;Folder does not appear to exist
MD "c:\temp\somefolder"
COPY "\\server\share\somefolder\*.*" "c:\temp\somefolder\*.*" /c /h /r /s
EndIf


 


Les
(KiX Master)
2006-03-20 10:39 PM
Re: Check if a directory exists

Well... I would think that the simple check would suffice, assuming that in the absense of said folder one were to be created. If a file did exist of the same name, the creation of the folder would fail.

NTDOCAdministrator
(KiX Master)
2006-03-20 11:22 PM
Re: Check if a directory exists

Yes correct it would. If I was going to do this in script I'd have much more logic and checks in place.

Basically meant that checking / verifying that someone did not have a file with that name would also be prudent, but as you pointed out would / should use much more logic and error checking.


digitaldeath
(Fresh Scripter)
2006-05-04 06:09 PM
Re: Check if a directory exists

Thanks guys!