Page 1 of 1 1
Topic Options
#159497 - 2006-03-20 03:14 PM Check if a directory exists
digitaldeath Offline
Fresh Scripter

Registered: 2006-03-08
Posts: 9
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.

Top
#159498 - 2006-03-20 03:19 PM Re: Check if a directory exists
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
same way, it works for both.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#159499 - 2006-03-20 03:22 PM Re: Check if a directory exists
digitaldeath Offline
Fresh Scripter

Registered: 2006-03-08
Posts: 9
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?


Edited by digitaldeath (2006-03-20 03:24 PM)

Top
#159500 - 2006-03-20 03:40 PM Re: Check if a directory exists
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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

_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#159501 - 2006-03-20 10:04 PM Re: Check if a directory exists
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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


 

Top
#159502 - 2006-03-20 10:39 PM Re: Check if a directory exists
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#159503 - 2006-03-20 11:22 PM Re: Check if a directory exists
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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.

Top
#159504 - 2006-05-04 06:09 PM Re: Check if a directory exists
digitaldeath Offline
Fresh Scripter

Registered: 2006-03-08
Posts: 9
Thanks guys!
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.207 seconds in which 0.169 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org