File: Class for accessing files or directories and querying their...

Description Usage Arguments Fields and Methods Author(s) Examples

Description

Package: R.io
Class File

Object
~~|
~~+--File

Directly known subclasses:

public static class File
extends Object

This class provides methods for accessing files or directories and check their attributes.

An idea of this class is to provide a system independent interface for accessing files and directories. One simple example is that one Windows system file.exists("C:/Windows") returns TRUE, whereas file.exists("C:/Windows/") returns FALSE. This type of different behaviours between different system are the class File trying to overcome.

Unfortunately, I do not have access to more than Unix and WinMe, so I have not been able to verify the correctness on other systems.

Usage

1
File(..., expandShortcuts=TRUE)

Arguments

...

A set of character strings or File objects specifying the path to a file or a directory. If "", the current directory is returned.

expandShortcuts

If TRUE, Windows shortcut files (*.lnk) are parsed and followed, otherwise just treated as regular files.

Fields and Methods

Methods:

as.character Gets a character string representation of the File object.
canRead Checks if the file can be read.
canWrite Checks if the file can be written to.
chooseFile -
createNewFile Creates a new file.
createTempFile Creates a temporary file name.
erase Deletes a file or a directory.
getAbsoluteFile Gets the absolute path as a File.
getAbsolutePath Gets the absolute pathname string.
getCanonicalFile Gets the cannonical form of this pathname.
getCanonicalPath Gets the cannonical pathname string.
getExtension Takes a filename and returns the extension.
getName Gets the name or directory specified by this pathname.
getParent Gets the string of the parent specified by this pathname.
getParentFile Gets the parent specified by this pathname.
getPath Gets the path specified by this pathname.
getWithoutExtension Takes a filename and returns the filename without the extension.
isAbsolute Checks if this pathname is absolute.
isDirectory Checks if the file specification is a directory.
isExisting Checks if a file or a directory exists.
isFile Checks if the file specification is a file.
lastModified Gets the time when the file was last modified.
listDir Gets the file names in the directory.
listFiles Gets the files in the directory.
mkdir Creates a directory.
mkdirs Creates a directory including any necessary but nonexistent parent directories.
print Prints information about the File object.
removeUps -
size Gets the size of the file.
split -
toURL Converts this abstract pathname into a URL.

Methods inherited from Object:
$, $<-, [[, [[<-, as.character, attach, attachLocally, clearCache, clone, detach, equals, extend, finalize, gc, getEnvironment, getFields, getInstanciationTime, getStaticInstance, hasField, hashCode, ll, load, objectSize, print, save

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
path <- Package("R.io")$path
file <- File(path, "DESCRIPTION")

cat("File             :", as.character(file), "\n")
cat("Can read         :", canRead(file), "\n")
cat("Can write        :", canWrite(file), "\n")
cat("Last modified    :", format(lastModified(file)), "\n")
cat("Size             :", size(file), "bytes\n")
cat("Name             :", getName(file), "\n")
cat("Path             :", getPath(file), "\n")
cat("Parent directory :", getParent(file), "\n")
cat("Canonical path   :", getCanonicalPath(file), "\n")
cat("URL              :", toURL(file), "\n")

path <- getParentFile(file)
cat("\nFiles in the same directory as", as.character(file), "\n")
print(listDir(path))

files <- listFiles(path)
cat("\nFile sizes for all files in", as.character(path), "\n")
for (file in files)
  cat(formatC(getName(file), width=20, flag="-"), "", formatC(size(file), width=6), "bytes\n")

HenrikBengtsson/R.io documentation built on May 6, 2019, 11:54 p.m.