Next Previous Contents

9. File Related Functions

9.1 BACKUP_BY_COPYING

Synopsis

Set the backup mode

Usage

Int_Type BACKUP_BY_COPYING

Description

If non-zero, backup files will be made by copying the original file to the backup file. If zero, the backup file will be created by renaming the original file to the backup file. The default for BACKUP_BY_COPYING is zero because it is fastest.

See Also

rename_file, copy_file

9.2 IsHPFSFileSystem

Synopsis

IsHPFSFileSystem

Usage

Integer IsHPFSFileSystem(String path);

Description

Returns non-zero if drive of path (possibly the default drive) is HPFS.

9.3 change_default_dir

Synopsis

change_default_dir

Usage

Integer change_default_dir (String new_dir);

Description

This function may be used to change the current working directory of the editor to new_dir. It returns zero upon success or -1 upon failure. Note: Each buffer has its own working directory. This function does not change the working directory of the buffer. Rather, it changes the working directory of the whole editor. This has an effect on functions such as rename_file when such functions are passed relative filenames.

See Also

setbuf_info, getbuf_info, rename_file

9.4 copy_file

Synopsis

copy_file

Usage

Integer copy_file (String src, String dest);

Description

This function may be used to copy a file named src to a new file named dest. It attempts to preserve the file access and modification times as well as the ownership and protection.

It returns 0 upon success and -1 upon failure.

See Also

rename_file, file_status

9.5 delete_file

Synopsis

delete_file

Usage

Integer delete_file (String file);

Description

This function may be used to delete a file specified by the file parameter. It returns non-zero if the file was sucessfully deleted or zero otherwise.

See Also

rmdir

9.6 directory

Synopsis

directory

Description

returns number of files and list of files which match filename. On unix, this defaults to filename*. It is primarily useful for DOS and VMS to expand wildcard filenames

9.7 expand_filename

Synopsis

expand_filename

Usage

String expand_filename (String file);

Description

The expand_filename function expands a file to a canonical form. For example, under Unix, if file has the value "/a/b/../c/d", it returns "/a/c/d". Similarly, if file has the value "/a/b/c//d/e", "/d/e" is returned.

9.8 extract_filename

Synopsis

extract_filename

Usage

String extract_filename (String filespec);

Description

This function may be used to separate the file name from the path of of a file specified by filespec. For example, under Unix, the expression

        extract_filename ("/tmp/name");
returns the string "name".
See Also

expand_filename

9.9 file_changed_on_disk

Synopsis

file_changed_on_disk

Usage

Integer file_changed_on_disk (String fn);

Description

This function may be used to determine if the disk file specified by the parameter fn is more recent than the current buffer.

See Also

file_time_compare, check_buffers

9.10 file_status

Synopsis

file_status

Usage

Integer file_status (String filename);

Description

The file_status function returns information about a file specified by the name filename. It returns an integer describing the file type: 2 file is a directory 1 file exists and is not a directory 0 file does not exist. -1 no access. -2 path invalid -3 unknown error

9.11 file_time_compare

Synopsis

file_time_compare

Usage

Integer file_time_cmp (String file1, String file2);

Description

This function compares the modification times of two files, file1 and file2. It returns an integer that is either positive, negative, or zero integer for file1 > file2, file1 < file2, or file1 == file2, respectively. In this context, the comparison operators are comparing file modification times. That is, the operator > should be read ``is more recent than''. The convention adopted by this routine is that if a file does not exist, its modification time is taken to be at the beginning of time. Thus, if f exists, but g does not, the file_time_compare (f, g) will return a positive number.

See Also

file_status, time

9.12 find_file

Synopsis

find_file

Usage

Integer find_file (String name);

Description

The find_file function switches to the buffer associated with the file specified by name. If no such buffer exists, one is created and the file specified by name is read from the disk and associated with the new buffer. The buffer will also become attached to the current window. Use the read_file function to find a file but not associate it with the current window.

See Also

read_file

9.13 insert_file

Synopsis

insert_file

Usage

Integer insert_file (String f);

Description

This function may be used to insert the contents of a file named f into the buffer at the current position. The current editing point will be placed at the end of the inserted text. The function returns -1 if the file was unable to be opened; otherwise it returns the number of lines inserted. This number can be zero if the file is empty.

See Also

read_file, find_file, insert

9.14 msdos_fixup_dirspec

Synopsis

msdos_fixup_dirspec

Usage

String msdos_fixup_dirspec (String dir);

Description

The motivation behind this is that DOS does not like a trailing backslash except if it is for the root dir. This function makes dir conform to that.

9.15 read_file

Synopsis

read_file

Usage

Integer read_file (string fn);

Description

The read_file function may be used to read a file specified by fn into its own buffer. It returns a non-zero value upon success and signals an error upon failure. The hook find_file_hook is called after the file is read in. Unlike the related function, find_file, this function does not create a window for the newly created buffer.

See Also

find_file, file_status, write_buffer

9.16 rename_file

Synopsis

rename_file

Usage

Integer rename_file (String old_name, String new_name);

Description

This function may be used to change the name of a disk file from old_name to new_name. Upon success, zero is returned. Any other value indicates failure. Note: Both filenames must refer to the same file system.

See Also

file_status, stat_file

9.17 set_file_translation

Synopsis

set_file_translation

Usage

set_file_translation (Integer n);

Description

This function affects only the way the next file is opened. Its affect does not last beyond that. If it the value of the parameter is 1, the next file will be opened in binary mode. If the parameter is zero, the file will be opened in text mode.


Next Previous Contents