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
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
#140081 - 2005-05-2002:49 PMRe: Checking file existance in Kixtart
KdyerKdyer
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
#140084 - 2005-05-2103:56 AMRe: Checking file existance in Kixtart
NTDOCNTDOC 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.
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?