Sei sulla pagina 1di 5

;###########################################################

;#
;# Author : PReS Connections
;# : http://www.presconnections.com
;#
;# File name : PRSFile.pdi
;# Version : 1.0
;# Date : 02nd September 2009
;#
;# Purpose : PRSFILE.dll examples
;#
;###########################################################

RECORD

INTERNAL

ALPHA aFrom L256


ALPHA aTo L256
ALPHA aReturnMessage L40
NUMERIC nResult

START
aFrom = "C:\\\\Test.txt"
aTo = "C:\\\\Temp\\\\Test.txt"

; Call subrouitne
nResult = GOSUB PRSFile(aFrom, aTo, 100)

PROMPT aReturnMessage

EXIT

;###########################################################
;#
;# SUBROUTINE PRSFile (Source file, Destination file, Action)
;#
;# Action Description
;# ====== ==========================================================
;# 100 Copy file
;# Copies the nominated file. The destination may be the current
;# directory, or a different drive/directory (providing it is valid).
;#
;# 101 Move file
;# Moves the nominated file. The destination may be the current
;# directory, or a different drive/directory (providing it is valid).
;#
;# 102 Rename file
;# Renames the current file. By definition, the assumption is that the
;# destination file is in the same directory (otherwise, a Move function
;# could have been used instead).
;#
;# 103 If - exist
;# This function tests to see if the nominated file is present.
;#
;#
;# 104 Get file info
;# This function retrieves information on the file: including size,
;# read/write access and date/time stamp. This function records information

;# in all 6 nArray elements.


;#
;# 105 Create directory
;# Used to Create a new directory
;#
;# 106 Change directory
;# Used to Change to an existing directory
;#
;# 107 Remove directory
;# Used to Remove an existing directory. An error occurs if the directory
;# is not empty
;#
;# 108 Copy/Overwrite
;# Allows printing to a network printer. This can also be used to overwrite

;# an existing file on disk.


;#
;# 109 Change File Attribute
;# Allows modification of the file attributes. See the topic, Change File
;# Attribute for more information.
;#
;# 110 Delete file
;# Removes the file. See the topic, Delete File for more information
;#
;#
;#
;###########################################################

SUBROUTINE PRSFile (a_source, a_destination, n_action)

ALPHA a_source L256


ALPHA a_destination L256
NUMERIC n_action

START

ALPHA a_FileInfo L26

; array used by Userhook


NUMERIC n_USERHOOK[6]
INITARRAY n_USERHOOK, 0

; Set file action


n_USERHOOK[0] = n_action

; Boolean 0 = False, 1 = True


NUMERIC b_delete_des
b_delete_des = 0 ; Default not to delet file

; Which action to preform


SWITCH (n_action){
CASE (100) ; Copy file
CASE (101) ; Move file
CASE (102) ; Rename file
CASE (108) ; Copy/Overwrite
DELETE a_destination ; Delete destination
file if already exists
USERHOOK "PRSFILE" , n_USERHOOK, a_source, a_destination ; call
userhook function
BREAK

CASE (104) ; Get file info


; Set the following up as global INTERNALS to access information outside of
SUBROUTINE
NUMERIC n_FileSzie
NUMERIC n_ReadAccess
NUMERIC n_WriteAccess
ALPHA a_LastModified L26
ALPHA a_Created L26
ALPHA a_LastAccessed L26

n_USERHOOK[5] = 0
USERHOOK "PRSFile" , n_USERHOOK, a_source, a_FileInfo

; File size
n_FileSzie = n_USERHOOK[2]
; Read access indicator: 1 = TRUE, 0 = FALSE
n_ReadAccess = n_USERHOOK[3]
; Write access indicator: 1 = TRUE, 0 = FALSE
n_WriteAccess = n_USERHOOK[4]

; Date Last Modified


a_LastModified = a_FileInfo

; Date Created
n_USERHOOK[5] = 1
USERHOOK "PRSFile" , n_USERHOOK, a_source, a_FileInfo
a_Created = a_FileInfo

; Date Last Accessed


n_USERHOOK[5] = 2
USERHOOK "PRSFile" , n_USERHOOK, a_source, a_FileInfo
a_LastAccessed = a_FileInfo

BREAK

CASE (103) ; If - exist


CASE (105) ; Create directory
CASE (106) ; Change directory
CASE (107) ; Remove directory
CASE (109) ; Change File Attribute
CASE (110) ; Delete file
USERHOOK "PRSFile" , n_USERHOOK, a_source
BREAK

CASE (111)
; Append file
; Allows the attachment of a file. See the topic, Append File for more
information
BREAK

DEFAULT
BREAK
}
GOSUB CheckReturnCode(n_USERHOOK[1])

RETURN(n_USERHOOK[1])

;###########################################################
;#
;# SUBROUTINE CheckReturnCode (PRSFILE return Code)
;#
;###########################################################

SUBROUTINE CheckReturnCode (n_code)

NUMERIC n_code

START

SWITCH (n_code){
CASE (0)
aReturnMessage = "Success"
BREAK
CASE (1)
aReturnMessage = "Source file doesn't exist"
BREAK
CASE (2)
aReturnMessage = "Target file exists"
BREAK
CASE (3)
aReturnMessage = "File/Path not found"
BREAK
CASE (4)
aReturnMessage = "Cannot move to a different device"
BREAK
CASE (5)
aReturnMessage = "Unknown error"
BREAK
CASE (6)
aReturnMessage = "Invalid function code"
BREAK
CASE (7)
aReturnMessage = "Error accessing file"
BREAK
CASE (8)
aReturnMessage = "Memory allocation error"
BREAK
CASE (9)
aReturnMessage = "Missing second filename"
BREAK
CASE (10)
aReturnMessage = "Target and source are the same"
BREAK
CASE (11)
aReturnMessage = "Directory is not empty"
BREAK
CASE (12)
aReturnMessage = "Insufficient space for return string"
BREAK
CASE (13)
aReturnMessage = "Target device full"
BREAK
CASE (14)
aReturnMessage = "Printer error"
BREAK
CASE (15)
aReturnMessage = "Network error"
BREAK
DEFAULT
aReturnMessage = "No message available"
BREAK
}

RETURN

PReS code Formatted : 13 March 2020, 10:35

Potrebbero piacerti anche