Page 1 of 1 1
Topic Options
#140078 - 2005-05-20 02:10 AM Checking file existance in Kixtart
Huffinagle Offline
Getting the hang of it
*****

Registered: 2002-09-04
Posts: 75
Loc: McMinnville, OR, USA
Is there a way to check if a file exists in a directory on a computer via kixtart?

I have a script that checks for a file version, but if the file doesn't exist in the first place the script won't copy the newer file to the directory.

Here's the script I have for checking file dates and copying the latest file to the local computer.
Code:
 
if ingroup ("BPSusers")
$Result = CompareFileTimes("x:\apps\accapps\05-06\bps_0506.adp", "c:\accapps\bps_0506.adp")
IF $Result = 1
COPY "x:\apps\accapps\05-06\bps_0506.adp" "c:\accapps\bps_0506.adp"
ENDIF
endif



Matthew

Top
#140079 - 2005-05-20 02:13 AM Re: Checking file existance in Kixtart
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Check-out the builtin EXIST() function, example:

Code:

if exist("e:\docs3")

?"file exists!"

else

?"file doesn't exist"

endif



-Shawn

Top
#140080 - 2005-05-20 01:48 PM Re: Checking file existance in Kixtart
NeedANewJob Offline
Fresh Scripter

Registered: 2005-04-01
Posts: 23
Or you could skip doing the additional exist() and include checking for more return codes than just the 1:

-3 = File2 couldn't be opened
-2 = File1 couldn't be opened
-1 = File1 is older than File2
0 = The files have the same date/time
1 = File2 is older than File1

Top
#140081 - 2005-05-20 02:49 PM Re: Checking file existance in Kixtart
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Hey Matthew,

You can simplify your code quite a bit:
Code:

if ingroup ("BPSusers") AND CompareFileTimes("x:\apps\accapps\05-06\bps_0506.adp", "c:\accapps\bps_0506.adp")
COPY "x:\apps\accapps\05-06\bps_0506.adp" "c:\accapps\bps_0506.adp"
endif



HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#140082 - 2005-05-20 07:56 PM Re: Checking file existance in Kixtart
Huffinagle Offline
Getting the hang of it
*****

Registered: 2002-09-04
Posts: 75
Loc: McMinnville, OR, USA
Thank you guys for all the recommendations. My new script works great. Here's a sample of the code.

Code:
 



if ingroup ("Busers")
IF EXIST ("c:\accapps\bps_0506.adp")
$Result = CompareFileTimes("x:\apps\accapps\05-06\bps_0506.adp", "c:\accapps\bps_0506.adp")
IF $Result = 1
COPY "x:\apps\accapps\05-06\bps_0506.adp" "c:\accapps\bps_0506.adp"
ENDIF
ELSE COPY "x:\apps\accapps\05-06\bps_0506.adp" "c:\accapps\bps_0506.adp"
ENDIF
endif




Top
#140083 - 2005-05-21 12:22 AM Re: Checking file existance in Kixtart
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
So... I see you didn't take any of the advice.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#140084 - 2005-05-21 03:56 AM Re: Checking file existance in Kixtart
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Well as I see it he did take Shawn's advice and use an If Exist.

However if his original statement is correct about not wanting the file to copy if it does not exist then his code is still wrong as it will copy. If on the other hand you don't want the file to copy if it is not found in the first place then Kent's code is smaller and more efficient for the task.

If InGroup("Domain\Busers") ; If user is not in group abort this section of code 
If Exist("c:\accapps\bps_0506.adp") ; If the file exists do more checking otherwise abort
$Result = CompareFileTimes("x:\apps\accapps\05-06\bps_0506.adp", "c:\accapps\bps_0506.adp")
If $Result = 1 ; If compared file on server is newer copy to client
Copy "x:\apps\accapps\05-06\bps_0506.adp" "c:\accapps\bps_0506.adp"
EndIf
Else ; File was not found so copy it
Copy "x:\apps\accapps\05-06\bps_0506.adp" "c:\accapps\bps_0506.adp"
EndIf
EndIf

Top
#140085 - 2005-05-23 08:53 PM Re: Checking file existance in Kixtart
Huffinagle Offline
Getting the hang of it
*****

Registered: 2002-09-04
Posts: 75
Loc: McMinnville, OR, USA
NTDOC,

Here's the pseudo code for what I wanted the script to do:
Code:
   
Check to see if the remote file is newer than the local file.
If remote file is newer, copy remote file over local file.
If local file doesn't exist, copy remote file to local folder.



By the way, do I have to DIM my $Result at the beginning of my script?

Example- DIM = $Result

Top
#140086 - 2005-05-23 09:18 PM Re: Checking file existance in Kixtart
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
It would be
DIM $Result

No = sign. Declaring variables is up to you. It is suggested that you do though.

Top
#140087 - 2005-05-23 11:10 PM Re: Checking file existance in Kixtart
Huffinagle Offline
Getting the hang of it
*****

Registered: 2002-09-04
Posts: 75
Loc: McMinnville, OR, USA
Thanks!
Top
#140088 - 2005-05-25 12:43 AM Re: Checking file existance in Kixtart
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See COMPAREFILETIMES() in the Kixtart Manual.
_________________________
There are two types of vessels, submarines and targets.

Top
#140089 - 2005-05-25 01:54 AM Re: Checking file existance in Kixtart
Huffinagle Offline
Getting the hang of it
*****

Registered: 2002-09-04
Posts: 75
Loc: McMinnville, OR, USA
Thanks for the tip Sealeopard. Here's my final code:
Code:
 

if ingroup ("Busers")
$Result = CompareFileTimes("x:\apps\accapps\05-06\bps_0506.adp", "c:\accapps\bps_0506.adp")
IF $Result = 1 or $Result = -3
COPY "x:\apps\accapps\05-06\bps_0506.adp" "c:\accapps\bps_0506.adp"
ENDIF
endif


Top
#140090 - 2005-05-25 05:06 PM Re: Checking file existance in Kixtart
NeedANewJob Offline
Fresh Scripter

Registered: 2005-04-01
Posts: 23
Like I said... ;-)
Top
Page 1 of 1 1


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

Who's Online
0 registered and 1418 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.098 seconds in which 0.061 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