[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
PrologFileIo

(Prolog) File I/O

File accessing predicates are:

Writing to file

% Visual Prolog 5.2
% Opens (or creates) a file 'C:\PrologTest.txt'
% If the file already exists, it is cleared first
% Then write text to the file and closes it.
DOMAINS
  FILE = myFile
GOAL
  openwrite(myFile,"c:\PrologTest.txt"),
  writedevice(myFile),
  write("My first Prolog file output!\n"),
  writedevice(myFile),
  closefile(myFile).


% Visual Prolog 5.2
% Assumes a file does not exists
% then create it
domains
  FILE = myFile
  
constants 
  myFilename = "temp.txt"
goal
  NOT(existfile(myFilename)),
  openappend(myFile,myFilename),
  closefile(myFile),
  existfile(myFilename),
  write("Succeeded!\n").


Change file attributes

% Visual Prolog 5.2
% This code saves data to a file
% and sets the file attributes to read-only
%
% Therefore, it will only run successfuly once.
DOMAINS
intList = integer*
FACTS
fact1(integer,string,intList)
fact2(integer,string)
CONSTANTS
fa_rdonly = 0x01
CLAUSES
fact1(1,"fact1",[1,2,3]).
fact1(2,"fact2",[1,3]).
fact1(3,"fact2",[3,2,1]).
fact2(1,"one").
fact2(1,"one once more").
fact2(2,"two").
GOAL
  Name = "C:\Bilderbikkel.txt",
  save(Name),
  fileattrib(Name,fa_rdonly).




Windows XP issues

Windows XP automatically defragments the harddisk. If you open a file for longer then 13 minutes without using it, the opened file might get moved. Therefore, do not open your files without using them [1].

Error 1215: Read/write attempt without input/output device

You can get the writedevice by .

Visual Prolog File I/O error list

7000	Error while calling of internal OS function. OS error code:
7002	File not found
7003	Path not found
7004	Out of handles
7005	Access denied
7006	Invalid handle
7012	Invalid access code
7015	Invalid disk drive
7016	Cannot remove current directory
7017	Not same device
7018	No more files
7019	Disk write-protected
7020	Unknown unit
7021	Drive not ready
7022	Unknown command
7023	Data error (CRC) 
7024	Bad request structure length
7025	Seek error
7026	Unknown type of medium
7027	Sector not found
7028	Printer out of paper
7029	Write fault
7030	Read fault
7031	General failure
7032	Sharing violation
7033	Lock violation
7034	Invalid disk change
7035	FCB unavailable
7036	Sharing buffer exceeded
7050	Unsupported network request
7051	Remote machine not listening
7052	Duplicate name on network
7053	Network name not found
7054	Network busy
7055	Device no longer exists on network
7056	NetBIOS command limit exceeded
7057	Error in network adapter hardware
7058	Incorrect response from network
7059	Unexpected network error
7060	Remote adapter incompatible
7061	Print queue full
7062	Insufficient memory for print file
7063	Print file canceled
7064	Network name deleted
7065	Network access denied
7066	Incorrect network device type
7067	Network name not found
7068	Network limit exceeded
7069	NetBIOS session limit exceeded
7070	File sharing temporarily paused
7071	Network request not accepted
7072	Print or disk redirection paused
7080	File already exists
7082	Cannot make directory
7083	Fail on Int 24H (critical error) 
7084	Too many redirections
7085	Duplicate redirection
7086	Invalid password
7087	Invalid parameter
7088	Network device fault
7108	Drive locked by another process
7110	Open/create failed due to explicit fail command
7111	Buffer too small
7112	Disk is full
7113	No more search handles
7114	Invalid target handle for DosDupHandle
7115	Bad user virtual address
7116	Error on display write or keyboard read
7117	Invalid DosDevIOCtl category
7118	Invalid value for verify flag
7119	Driver does not support DosDevIOCtl
7120	Invalid function called
7122	Insufficient data in buffer
7123	Invalid character or bad filename
7125	No volume label found
7130	Invalid handle operation for direct disk access
7131	Cannot seek to negative offset
7132	Cannot seek on pipe or device
7142	Drive is busy


'File I/O' links

Code links

References



last edited (February 28, 2007) by bilderbikkel, Number of views: 4677, Current Rev: 16 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.