(LOGO.JPG) Python for OpenVMS

(go to: table of contents, index, list of vms_lib, prev: DAY_OF_WEEK, next: DELETE_LOGICAL)


DELETE_FILE - Delete One or More Files


Format:
    status, context, resultant_name = vms_lib.delete_file ( \
                filespec [,default-filespec] [,related-filespec] \
                [,user-success-procedure] [,user-error-procedure] \
                [,user-confirm-procedure] [,user-specified-argument] \
                [,file-scan-context])
Returns:
status
Return code from LIB$DELETE_FILE.
context
Updated 'file-scan-context'. If this argument is omitted (or None), then 0 is returned.
resultant_name
The RMS resultant file specification of the last file processed.
Arguments:
filespec
File specification of the files to be deleted. Can include wildcards.
default-filespec
Default file specification of the files to be deleted.
See the OpenVMS Record Management Services Reference Manual for information about default file specifications.
related-filespec
Related file specification of the files to be deleted.
See the OpenVMS Record Management Services Reference Manual for information about related file specifications.
user-success-procedure
User-supplied success routine that LIB$DELETE_FILE calls after it successfully deleted a file. See the examples section for the arguments to this routine.
user-error-procedure
User-supplied error routine that LIB$DELETE_FILE calls when it detects an error. Return with the value 1 to tell LIB$DELETE_FILE to contine. Return with the value 0 to tell LIB$DELETE_FILE to stop processing immediately. See the examples section for the arguments to this routine.
user-confirm-procedure
The confirm-procedure can make more checks to determine if the current file should be deleted. If confirm routine returns a success status (bit 0 set), the file is then deleted; otherwise, the file is not deleted. See the examples section for the arguments to this routine.

WARNING!Changes to the FAB can lead to crashes after returning from the user-confirm-procedure back to LIB$DELETE_FILE !!

user-specified-argument
This can be any Python object (including None) that is passed unchanged to the user-procedures.
file-scan-context
Context for deleting a list of file specifications. Supply a value of 0 for the first call. The context can be deallocated by calling the vms_lib.file_scan_end() routine with the context as its argument.
Examples:
>>> import vms_lib
>>> import vms_sys


>>> # define user-procedures

>>> # user-success
>>> def u_success (filespec, user_arg):
...   print '*user-success-procedure'
...   print type(filespec), filespec
...   print type(user_arg), user_arg
...   return 1
... #-u_success
>>>

>>> # user-error
>>> def u_error (filespec, l_rms_sts, l_rms_stv, \
...            l_error_source, user_arg):
...   print '*user-error-procedure'
...   print type(filespec), filespec
...   print type(l_rms_sts), l_rms_sts
...   print type(l_rms_stv), l_rms_stv
...   print type(l_error_source), l_error_source
...   print type(user_arg), user_arg
...   return 1
... #-u_error
>>>

>>> # user-confirm
>>> def u_confirm (filespec, fab, user_arg):
...   print '*user-confirm-procedure'
...   print type(filespec), filespec
...   print type(fab), fab
...   print fab.FNA
...   print type(user_arg), user_arg
...   return 1
... #-u_confirm
>>>



>>> # simple delete-test
>>> file = open ('DELETE.TMP','w')
>>> file.close()

>>> vms_lib.delete_file ('delete.tmp;', None, None, \
...                      u_success, u_error, u_confirm, 'uspec-arg')
*user-confirm-procedure
<type 'string'> USER_HERE:[ZESSIN.DELETE]DELETE.TMP;1
<type 'vmsobj_fab'> <vmsobj_fab, FAB at 0x7fee81bc>
delete.tmp;              <-- fab.FNA
<type 'string'> uspec-arg
*user-success-procedure
<type 'string'> USER_HERE:[ZESSIN.DELETE]DELETE.TMP;1
<type 'string'> uspec-arg
(1, 0, 'USER_HERE:[ZESSIN.DELETE]DELETE.TMP;1')
>>> # Note: 1 = status, 0 = context

>>> # see if file has been deleted ...
>>> import os; os.system ('DIRECTORY DELETE.TMP')
%DIRECT-W-NOFILES, no files found
98960        <-- return status from subprocess
>>>


>>> # try to delete an open file (triggers error-procedure)
>>> file = open ('DELETE.TMP','w')
>>> vms_lib.delete_file ('delete.tmp;', None, None, \
...                      u_success, u_error, u_confirm, 'uspec-arg')
*user-confirm-procedure
<type 'string'> USER_HERE:[ZESSIN.DELETE]DELETE.TMP;1
<type 'vmsobj_fab'> <vmsobj_fab, FAB at 0x7fee81bc>
delete.tmp;              <-- fab.FNA
<type 'string'> uspec-arg
*user-error-procedure
<type 'string'> USER_HERE:[ZESSIN.DELETE]DELETE.TMP;1
<type 'int'> 98954    <-- rms_sts
<type 'int'> 2048     <-- rms_stv
<type 'int'> 1        <-- error-source, 1= error deleting file
<type 'string'> uspec-arg
(1409065, 0, 'USER_HERE:[ZESSIN.DELETE]DELETE.TMP;1')
>>> file.close()
>>>
>>> vms_sys.getmsg (98954) # rms_sts
('%RMS-E-FLK, file currently locked by another user', (0, 0, 0, 0))
>>> vms_sys.getmsg (2048)  # rms_stv
('%SYSTEM-W-ACCONFLICT, file access conflict', (0, 0, 0, 0))
>>>
>>> vms_sys.getmsg (1409065)
('%LIB-S-ERRROUCAL, error routine called', (0, 0, 0, 0))
>>>

>>> # see if file has been deleted ...
>>> import os; os.system ('DIRECTORY DELETE.TMP')

Directory USER_HERE:[ZESSIN.DELETE]

DELETE.TMP;1

Total of 1 file.
1            <-- return status from subprocess
>>>



>>> # example of wildcard delete with context
>>> file = open ('DELETE1.TMP','w'); file.close()
>>> file = open ('DELETE2.TMP','w'); file.close()
>>> file = open ('DELETE3.TMP','w'); file.close()
>>> context = 0
... status, context, resultant_name = \
...   vms_lib.delete_file ('delete*.tmp;', None, None, \
...     u_success, u_error, u_confirm, 'uspec-arg', context)
... print status, context, resultant_name
*user-confirm-procedure
<type 'string'> USER_HERE:[ZESSIN.DELETE]DELETE1.TMP;1
<type 'vmsobj_fab'> <vmsobj_fab, FAB at 0x7fee81bc>
delete*.tmp;
<type 'string'> uspec-arg
*user-success-procedure
<type 'string'> USER_HERE:[ZESSIN.DELETE]DELETE1.TMP;1
<type 'string'> uspec-arg
*user-confirm-procedure
<type 'string'> USER_HERE:[ZESSIN.DELETE]DELETE2.TMP;1
<type 'vmsobj_fab'> <vmsobj_fab, FAB at 0x7fee81bc>
delete*.tmp;
<type 'string'> uspec-arg
*user-success-procedure
<type 'string'> USER_HERE:[ZESSIN.DELETE]DELETE2.TMP;1
<type 'string'> uspec-arg
*user-confirm-procedure
<type 'string'> USER_HERE:[ZESSIN.DELETE]DELETE3.TMP;1
<type 'vmsobj_fab'> <vmsobj_fab, FAB at 0x7fee81bc>
delete*.tmp;
<type 'string'> uspec-arg
*user-success-procedure
<type 'string'> USER_HERE:[ZESSIN.DELETE]DELETE3.TMP;1
<type 'string'> uspec-arg
>>> print status, context, resultant_name
1 2281736 USER_HERE:[ZESSIN.DELETE]DELETE3.TMP;1
>>>


@@ more DELETE_FILE examples
>>>

(go to: table of contents, index, list of vms_lib, prev: DAY_OF_WEEK, next: DELETE_LOGICAL)

02-APR-1999 ZE.